[wp-trac] [WordPress Trac] #15292: It's not possible to check for "meta_value = 0" in wp_query->get_posts

WordPress Trac wp-trac at lists.automattic.com
Fri Mar 4 03:45:57 UTC 2011


#15292: It's not possible to check for "meta_value = 0" in wp_query->get_posts
---------------------------------+-----------------------------
 Reporter:  hetjens              |       Owner:  dd32
     Type:  defect (bug)         |      Status:  accepted
 Priority:  normal               |   Milestone:  Future Release
Component:  Query                |     Version:  3.0.1
 Severity:  major                |  Resolution:
 Keywords:  3.2-early has-patch  |
---------------------------------+-----------------------------
Description changed by scribu:

Old description:

> Because of the "empty" function of php it isn't possible to check for a
> meta_value = 0 in wp_query->get_posts.
>
> My Case:
> ...
> 'meta_key' => '_menu_item_menu_item_parent',
> 'meta_value' => '0',
> ...
>
> wp-includes/query.php Line 2307 is:
> if ( ! empty($q['meta_value']) ) {
>
> But empty says that String "0" is true (look here:
> http://ch2.php.net/empty )
>
> So the query will return all posts that have a meta-field
> "_menu_item_menu_item_parent" and not only the posts with
> "_menu_item_menu_item_parent = 0" (which means, that it's an menu root
> item)
>
> My solution is:
> if (( ! empty($q['meta_value']) ) || ($q['meta_value'] == '0')) {
>
> but that's not very nice. Any better idea?
>
> Thanks,
> Philip

New description:

 Because of the "empty" function of php it isn't possible to check for a
 meta_value = 0 in wp_query->get_posts.

 My Case:

 {{{
 'meta_key' => '_menu_item_menu_item_parent',
 'meta_value' => '0',
 }}}

 wp-includes/query.php Line 2307 is:
 {{{if ( ! empty($q['meta_value']) ) {}}}

 But empty() says that String "0" is true

 So the query will return all posts that have a meta-field
 "_menu_item_menu_item_parent" and not only the posts with
 "_menu_item_menu_item_parent = 0" (which means, that it's an menu root
 item)

 My solution is:

 {{{
 if (( ! empty($q['meta_value']) ) || ($q['meta_value'] == '0')) {
 }}}

 but that's not very nice. Any better idea?

 Thanks,
 Philip

--

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15292#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list