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 From Bootstrap to WordPress Create Bootstrap Styled Theme Templates Creating a Portfolio Landing Page

I cannot get the wp_query to work. I have copied the code exactly as shown in the tutorial but nothing shows up.

<div class="row">

    <?php 

        $args = array(
            'post_type' => 'portfolio'
        );
        $the_query = new WP_Query($args);

    ?>

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

    <div class="col-sm-3 portfolio-piece">

        <p><?php the_post_thumbnail('medium'); ?></p>
        <h3><?php the_title(); ?></h3>

    </div>

    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>

</div>

3 Answers

karennh
karennh
4,925 Points

It may be a silly question but is your custom post type called 'portfolio'? And you have entered something as a portfolio post? What happens? Do you get an error? Do you get any output at all?

Yes, I have a few portfolio posts! I have confirmed that they exist but cannot get the posts to output using the code I copied above.

karennh
karennh
4,925 Points

I can't see anything wrong with this code, but I wonder what comes before it.

If I were you, I'd try to do some debugging by outputting some messages like: <?php echo "I made it where the thumbnail should be" ?>

Jill Ferron
Jill Ferron
5,023 Points

Check it the page in question is set as your static front page or not. If it is, WP will ignore the Portfolio Grid template you set in the admin area and automatically use the front-page.php template instead.