#21618 closed defect (bug) (fixed)
WP_Query should accept menu_order as a query arg
Reported by: | wonderboymusic | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | 2.0 |
Component: | Query | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
With custom post types, you can use the Posts table for basically anything. menu_order
can be especially useful for holding foreign ids (after you add an index to it). The problem is that menu_order
can't be passed to WP_Query
:
add_filter( 'query', function ( $sql ) { error_log( $sql ); return $sql; } ); $stuff = new WP_Query( array( 'menu_order' => 5 ) ); exit(); // SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10
My patch fixes that, the result is now:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.menu_order = 5 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10
Attachments (1)
Change History (7)
Note: See
TracTickets for help on using
tickets.
Adding it to the public query vars list means it can be accessible via the URL, so ?menu_order=1. That does not seem to be desirable to expose on the frontend.
Adding it to the private query vars list means it can be passed to wp(). While not an issue of disclosure, I've only ever added things to that list that we needed in wp_edit_posts_query() or wp_edit_attachments_query().
Adding it to WP_Query, as the other part of the patch does, seems sufficient.