[wp-trac] [WordPress Trac] #29447: Multiple options for 'orderby' => 'meta_value_num' or making it optional
WordPress Trac
noreply at wordpress.org
Mon Sep 1 06:43:11 UTC 2014
#29447: Multiple options for 'orderby' => 'meta_value_num' or making it optional
-----------------------------------+-----------------------------
Reporter: wzislam | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.9.2
Severity: normal | Keywords:
Focuses: template, performance |
-----------------------------------+-----------------------------
The issue is regarding the {{{WP_Query()}}} and {{{ 'orderby' =>
'meta_value_num' }}}:
{{{
$args = array(
'cat' => 5,
'posts_per_page' => 8,
'meta_key' => 'custom_sort_order',
'order' => 'ASC',
'orderby' => 'meta_value_num'
);
$custom_query = new WP_Query( $args );
}}}
With the code above I can sort my posts with my custom field's value
order, ascending. But if I forgot to assign the Custom Field key and value
with the post, the query doesn't find the whole post because of the
{{{custom_sort_order meta_key}}} — because it doesn't exist with that
certain post.
But I need to put the {{{'meta_key' => 'custom_sort_order'}}} there
because the Codex says:
{{{'meta_value_num'}}} - Order by numeric meta value (available with
Version 2.8). Also note that a {{{'meta_key=keyname'}}} must also be
present in the query.
At present there's no way to define multiple sort order criteria.
Can we have that in any of the upcoming version?
I'm afraid, this is my first trac ticket. We've discussed the issue in
[http://wordpress.stackexchange.com/q/147757/22728 this WordPress
StackExchange thread].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29447>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list