I am working on a site with three different main 'topevel' sections, that act as the top level parents of the site.
Each toplevel section has children and grandchildren, and there needs to be a listing of the top 4 most popular descendant pages of each child section. I am currently gathering the most popular pages using a metakey, which works great. the wp_query I'm using however is only returning immediate children.
get_pages won't work here because the metakey sorting is not working, nor will it allow me to limit to just 4 pages . This is my current code.
<?php $popularpost = new WP_Query( array( 'posts_per_page' => 4, 'post__not_in'=> array(220), 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post_type' => 'page', 'post_parent' => $parentid ) ); while ( $popularpost->have_posts() ) : $popularpost->the_post(); ?> <a href="<?php the_permalink(); ?>" class="cta"><?php the_title(); ?></a> <?php endwhile; wp_reset_postdata(); ?>