[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
Tue Nov 2 15:36:25 UTC 2010
#15292: It's not possible to check for "meta_value = 0" in wp_query->get_posts
--------------------------+-------------------------------------------------
Reporter: hetjens | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.0.1
Severity: major | Keywords: query, get_post, meta, meta_value
--------------------------+-------------------------------------------------
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
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15292>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list