WP_Query including all child pages excluding pages with children of their own
-
Hi all,
I am trying to display all the children of a page but I want to exclude any pages that have children of their own.
In the below code, the WP_Query is actually holding all the pages, including those with children. I am only not outputting them which is creating havoc in pagination.
I am new to WordPress coding, so anything that you see which is not right, please give me a shout and let me know.
global $post; $ourCurrentPage = get_query_var('paged'); $mypages = new WP_Query(array( 'post_type' => 'page', 'post_parent' => $post->ID, 'showposts' => 10, 'paged' => $ourCurrentPage, 'order' => desc, 'orderby' => ID )); if ($mypages->have_posts()) : while ($mypages->have_posts()) : $mypages->the_post(); $children = get_pages( array( 'child_of' => $post->ID ) ); $count_of_children = count( $children ); if( $count_of_children == 0 ) { ?> <div class="bdl-child-pages"> <h2><?php the_title(); ?></h2> <div class="entry page-<?php echo the_ID(); ?>"><?php echo the_content(); ?></div> <div class="bdl-read-more"><a class="button" href="<?php the_permalink(); ?>">Read more...</a></div> </div> <?php //return false; } else { $pages_with_children++; } endwhile; ?> <div class="bdl-pagination woocommerce-pagination"> <?php //echo paginate_links(array('total' => $mypages->max_num_pages - $pages_with_children)); //echo '<br>'; echo paginate_links(array('total' => $mypages->max_num_pages)); ?> <div> <?php endif; wp_reset_postdata(); ?>
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WP_Query including all child pages excluding pages with children of their own’ is closed to new replies.