I have a WordPress function that uses WP_Query on a custom post type, and then within the loop that displays the results, for each result there is a get_posts query that grabs the child posts of the result. I am trying to order the child posts, but nothing is working, they stay in their menu order. Does anybody know how to order a query within a query?
Here is the basic code:
// Query - Get all of the themes
remove_all_filters('posts_orderby');
$the_query = new WP_Query(array(
'post_type' => 'theme',
'posts_per_page' => -1,
'meta_key' => 'wpcf-theme-age-field',
'orderby' => 'meta_value',
'order' => ASC
) );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
// Gets the sessions posts that are children of this theme AND are within the season parameter
$childargs = array(
'post_type' => 'class-session',
'numberposts' => -1,
'meta_query' => array(
'relation' => 'AND',
array('key' => '_wpcf_belongs_theme_id', 'value' => $postid ),
array('key' => 'wpcf-edu-season', 'value' => $season ),
'meta_key' => 'wpcf_day_of_the_week',
'orderby' => 'meta_value',
'order' => 'ASC',
)
);
$child_posts = get_posts($childargs);