Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#21618 closed defect (bug) (fixed)

WP_Query should accept menu_order as a query arg

Reported by: wonderboymusic's profile wonderboymusic Owned by: ryan's profile 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)

menu-order-arg.diff (875 bytes) - added by wonderboymusic 12 years ago.

Download all attachments as: .zip

Change History (7)

#1 @nacin
12 years ago

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.

#2 @wonderboymusic
12 years ago

patch updated like whoa

#3 @Mamaduka
12 years ago

  • Cc georgemamadashvili@… added

#4 @nacin
12 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 3.5

#5 @ryan
12 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21748]:

Allow querying by menu_order. Props wonderboymusic. fixes #21618

#6 @azaozz
12 years ago

In [21756]:

Add menu_order to fill_query_vars(), see #21618

Note: See TracTickets for help on using tickets.