0

I have a custom WP_Query that looks like this:

$this_page_id=$wp_query->post->ID; 
 $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):

$this_page_id=$wp_query->post->ID; 
     $images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id, 'orderby' => 'menu_order' ) );
3
  • 1
    try adding 'order' => 'ASC' and see if anything changes... Commented Nov 29, 2011 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
    Commented Nov 29, 2011 at 4:41
  • Add it as an answer if you want the reputation, your answer was correct!
    – Brian
    Commented Nov 29, 2011 at 4:41

1 Answer 1

1

This query should work.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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