[wp-trac] [WordPress Trac] #32224: delete_post_meta() not working as expected when $meta_value is specified as 0 or '0'
WordPress Trac
noreply at wordpress.org
Fri May 1 15:10:59 UTC 2015
#32224: delete_post_meta() not working as expected when $meta_value is specified as
0 or '0'
--------------------------------+---------------------------
Reporter: husobj | Owner: boonebgorges
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 4.3
Component: Options, Meta APIs | Version: 4.2.1
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------------+---------------------------
Comment (by boonebgorges):
Replying to [comment:3 sc0ttkclark]:
> delete_metadata uses this:
>
>
> {{{
> if ( $meta_value )
> $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value );
> }}}
>
> It should probably be:
>
> {{{
> if ( '' !== $meta_value && null !== $meta_value )
> $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value );
> }}}
It's possible to add an empty string as metadata, so we don't want to
remove the ability to delete empty-string meta values.
If this were the last argument passed to `delete_metadata()`, we could use
`func_num_args()` to see if a value had been passed at all. But we also
want it to be possible to specify falsey values for `$meta_value` while
passing a value for `$delete_all`. To the unit tests, Batman!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32224#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list