Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

WP loop not working

I am using the loop below in WordPress but it is not pulling all of the 4 posts onto one page.

I have changed all pages to use the same custom template.

The custom template is working.

If anyone has insight to this problem please share.

Thanks in advance.

<?php
/**
 * Template Name: One Page Site
 *
 * @package One Page Theme
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
TEST!!!!!!
    <?php
        $args = array(
            'post_type' => 'page',
            'order' => 'ASC');
        $the_query = new WP_Query( $args );
    ?>

    <?php if ( have_posts() ): while ( $the_query->have_posts() ) : $the_query->the_post(); ?>  

    <?php get_template_part( 'content', 'page' ); ?>

    <?php endwhile; endif; ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Check your code

Check your code

1 Answer

Hi Carla,

You just forgot to add $the_query if ( $the_query->have_posts() ) :