Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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' ) );
share|improve this question
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

1 Answer 1

up vote 1 down vote accepted

This query should work.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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