[wp-trac] [WordPress Trac] #24933: update_metadata() returns true even if meta value not updated
WordPress Trac
noreply at wordpress.org
Sat Aug 3 08:33:36 UTC 2013
#24933: update_metadata() returns true even if meta value not updated
-------------------------+------------------------------
Reporter: jdgrimes | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.6
Severity: normal | Resolution:
Keywords: |
-------------------------+------------------------------
Comment (by leewillis77):
I can reproduce this as follows.
Create a post meta value by calling
{{{
update_metadata( 'post', 1, '_test', 'value1' );
}}}
Then, call it with a prev_value of value1, e.g.
{{{
update_metadata( 'post', 1, '_test', 'value2', 'value1' );
}}}
update_metadata() will return true.
Call the same update again. update_metadata() will return true despite the
fact that no metadata was updated. Hooks also fire as if the meta has been
updated. The attached patch checks the return value from $wpdb->update and
only returns true if rows were updated. This solves the original
reporter's issue.
The patch also only fires updated_post_meta and updated_postmeta hooks,
and invalidates the cache if the update changed rows. This seems logical
but could do with a second set of eyes to avoid back-compat headaches.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/24933#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list