[wp-trac] [WordPress Trac] #15388: get_posts does not order by menu_order
WordPress Trac
wp-trac at lists.automattic.com
Thu Nov 11 16:11:14 UTC 2010
#15388: get_posts does not order by menu_order
--------------------------+-------------------------------------------------
Reporter: ggus | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.0.1
Severity: normal | Keywords: menu_order get_posts orderby
--------------------------+-------------------------------------------------
I'm writing a plugin that makes use of custom post_types. The plugin (in
the back-end) aims to manage a group of custom posts children of the
actually edited custom post. I manage the ordering via the menu_order.
a statement like
{{{
get_posts('post_type=whatever&post_parent='.$post->ID.'$orderby=menu_order&order=ASC')
}}}
does not order by menu_order, instead it returns the elements ordered by
the default order (id?)
As reported in
[http://wordpress.org/support/topic/get_posts-not-using-
orderbymenu_order#post-1006470]
and also as stated in this bug fix:
[http://core.trac.wordpress.org/ticket/6731]
there is in the core file query.php at line 2147 (WP Version 3.0.1)
{{{
switch ( $orderby ) {
case 'menu_order':
break;
}}}
In this way every request to order by menu_order gets ignored.
It seems that query_posts function is unaffected by this, so
{{{
query_posts(array('post_type' => 'whatever', 'post_parent' => $post->ID ,
'order' => 'ASC', 'orderby' => 'menu_order'));
}}}
does work, but I fear there are some implications in using query_posts
instead of get_posts.
There is a solution proposed in the same page
[http://wordpress.org/support/topic/get_posts-not-using-
orderbymenu_order#post-1006470]
that fixes the bug by changing the code to
{{{
case 'menu_order':
$orderby = "$wpdb->posts.menu_order";
break;
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15388>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list