WordPress.org

Ready to get started?Download WordPress

Forums

get_posts not using orderby=menu_order (7 posts)

  1. blackc2004
    Member
    Posted 6 years ago #

    Hi there, based on the get_posts documenation http://codex.wordpress.org/Template_Tags/get_posts I should be able to use any column in the wp_posts table to sort entries. However, when I use menu_order (which has values in the table) it is not changing the sort order.

    Is this the correct usage?
    $myposts = get_posts('post_type=page&post_parent=80&orderby=menu_order&numberposts=');

  2. moshu
    Member
    Posted 6 years ago #

    To be honest, I do't see anything on that page mentioning "menu_order".
    Only Pages have menu order, btw.

  3. blackc2004
    Member
    Posted 6 years ago #

    Nothing on that page specifically says that, but there is a line that says "Note: The $orderby value can be the name of any field in the wp_posts table."

    And menu_order is a column in the wp_posts table.

  4. moshu
    Member
    Posted 6 years ago #

    Hmmm...
    see the history:
    http://codex.wordpress.org/index.php?title=Template_Tags/get_posts&action=history
    and Schulte's notes on July 12, 2005. Keyword: "assume".

    Since there is no possibility to define anything as "menu_order" for the posts (as you have in the Write Page subpanel), I think, no, I assume it does'nt really work for posts :)

  5. blackc2004
    Member
    Posted 6 years ago #

    Actually, I am using get_posts to get pages (post_type=page). So you would assume it would work. But we all know what assuming can do. :)

    I guess this should be filed as a bug then, or the codex updated? Or is there another way that I should be getting pages in this manner?

    get_posts('post_type=page&post_parent=80&orderby=menu_order&numberposts=');

    Thanks!

  6. blackc2004
    Member
    Posted 6 years ago #

    Ah, I was able to resolve this by using get_pages and sort_column as one of the params.
    See: http://wordpress.taragana.net/nav.html?wp-includes/post.php.source.html#l1014

    For more info.

  7. teonsight
    Member
    Posted 5 years ago #

    WP 2.7, wp-includes/query.php at line 2041 seems like not having code for case "menu_order"

    Change

    case 'menu_order':
      break;

    to

    case 'menu_order':
      $orderby = "$wpdb->posts.menu_order";
      break;

    and it will work. Write this change down somwhere :)
    Strange it's not implemented.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.