3

We can order pages by title.

Also we can sort them by menu_order.

Is it possible, to order pages by menu_order and title at the same time?

9

Use 'orderby' => 'title menu_order' or &orderby=title menu_order (depending of the syntax you use for your query parameters).

5
  • Wow. Does that work? I'll have to try it out... It doesn't look like it should from the source... – goldenapples Oct 19 '10 at 21:20
  • See line 2139, wp-includes/query.php – sorich87 Oct 19 '10 at 21:54
  • Yup, its in there. Thanks - I never realized that was possible! – goldenapples Oct 20 '10 at 16:52
  • It doesn't seem to be documented anywhere. I actually discovered it while browsing through the code. :) – sorich87 Oct 20 '10 at 18:15
  • wow... didn't know. looked in the codex and learned alot: none makes it empty and it really is an array exploded by spaces. already added it to the codex. – kaiser Feb 4 '11 at 5:10
2

I don't yet have enough rep to comment so I will have to post this tidbit as an answer instead.

Since WP 4.0, you may compound any of the available orderby values by padding them as a space-delimited list.

This is somewhat documented here

orderby will also parse a space-delimited set of columns:

$q = new WP_Query( array( 'orderby' => 'title author' ) );

Prior to 4.0, there was a problem: the value for order would only be applied to the last value that you passed in that space-delimited list, producing an ORDER BY clause like:

ORDER BY post_title, post_author DESC

In answer to your question, you may use 'orderby' => 'menu_order title'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.