[wp-trac] [WordPress Trac] #25538: WP_Query: OR relation breaks orderby meta_value
WordPress Trac
noreply at wordpress.org
Tue Oct 8 10:12:56 UTC 2013
#25538: WP_Query: OR relation breaks orderby meta_value
--------------------------+-----------------------------
Reporter: darrengrant | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: major | Keywords:
--------------------------+-----------------------------
When using the WP_Query class either for a custom query or the main query
using an OR relation in a meta_query will prevent orderby meta_value
working as it should. For instance:
{{{
$args = array(
'post_type' => 'post',
'meta_key' => 'order',
'meta_value' => 1,
'meta_compare' => '>=',
'orderby' => 'meta_value'
);
}}}
will render in a different order to:
{{{
$args = array(
'post_type' => 'post',
'meta_key' => 'order',
'meta_value' => 1,
'meta_compare' => '>=',
'orderby' => 'meta_value',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'order',
'compare' => '>=',
'value' => 1
)
)
);
}}}
Even though the two queries are the same. Replacing the relation with AND
will give the correct ordering however. Obviously this isn't a useful
real-world example, but highlights the issue best.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25538>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list