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

The page ABOUT in the stage Adding Content in custom Places, Part 1, it doesn’t show the testimonials.

The page ABOUT in the stage Adding Content in custom Places, Part 1, it doesn’t show the testimonials. I revised carefully the code and apparently everything looks right. I checked Custom Fields testimonials and about pages in the WP dashboard and everything looks fine. I’m stuck in this stage. Any help?

<div class="divider grid_12"> <h5>Testimonial</h5> </div>

<?php

$args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => 1,
    'orderby' => 'rand'
);

$the_query = new WP_Query( $args );
?>


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

    <div class="testimonial push_2 grid_10 clearfix">
        <blockquote>&ldquo; <?php the_field( 'testimonial' ); ?> &rdquo;</blockquote>
        <cite>&mdash; <?php the_field( 'name' ); ?></cite>
    </div>

<?php endwhile; else: ?>

3 Answers

Andrew Shook
Andrew Shook
31,709 Points

You need to add "$the_query->" before the have_posts() method. Right now you are running have_posts() on the standard query loop and not your custom query loop. Since your testimonials page is most likely empty you are not getting anything to show up on the page

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

Thanks Andrew. I will keep this answer when I get to that point again. I started from the beginning the whole process about how to build a WordPress Theme. I did that because it passed almost a week and nobody share some directions how to solve that problem. But anyway, I think to start again the whole process is kind of reward about more knowledge.

Thanks

Thanks Andrew for taking time to revise the code y provide your answer but adding $the_quary-> before heve post nothing happened. But after several revisions and wrote many times the code, I found that a coma and mispealings were in a wrong place.