include(locate_template) messing up the loop

I found the problem here. It was with the $this_page variable, it was referencing the homepage still and kept the about page from working. I had to simply modify how it was pulling the page ID and storing it.

Here’s my amended code.

<?php
/* Template Name: Page- Home */
get_header(); ?>

<?php 
  $this_page=get_the_ID();
  $loop = new WP_Query( array('post_type'=>'page', 'posts_per_page' => -1, 'post_parent' => $this_page, 'orderby' => 'menu_order', 'order' => 'ASC') ); 
  while ( $loop->have_posts() ) : $loop->the_post(); 
  $template = get_post_meta( $post->ID, '_wp_page_template', true );
?>  

  <?php include(locate_template(array($template), false, true)); ?>

<?php endwhile; wp_reset_query(); ?>

<?php get_footer(); ?>

Leave a Comment