I have a custom WP_Query that looks like this:

 $images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id ) );

My problem is that when using the orderby parameter (see here: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) to sort by menu_order (which I need to do for the project). The sort order is not working.

I'm 99% certain the reason it's not working is because I'm directing it to query all children of a specific post and the orderby parameter doesn't "dig that deep into the query" if that makes sense to anyone.

Can anyone offer some help? doing this (the expected solution yields nothing):

     $images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id, 'orderby' => 'menu_order' ) );
  • 1
    try adding 'order' => 'ASC' and see if anything changes... – Joshua Abenazer Nov 29 '11 at 4:34
  • So funny! I had tried that before but had a separate error which I later found and then forgot to go back and re-add order => ASC. Thanks! – Brian Nov 29 '11 at 4:41
  • Add it as an answer if you want the reputation, your answer was correct! – Brian Nov 29 '11 at 4:41

This query should work.

$images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id, 'orderby' => 'menu_order', 'order' => 'ASC' ) );
| improve this answer | |

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.