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 Add Bootstrap Components to WordPress Theme Setting Up a Bootstrap Slideshow Carousel

I can't get the wp_query to work in this stage, even when just displaying the title.

<?php 
                $args = array(
                   'post_type' => 'post',
                   'category_name' => 'featured'
                );
                $the_query = new WP_Query($args);
            ?>

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

2 Answers

Hi Mina,

Just as a heads up I edited your post just to fix up some of the code embedding, it wasn't completely displayed within a code block, also if you use the language after the first 3 ticks, in this case php, it will help with syntax highlighting.

You are very close! You are just missing the query variable before the initial have_posts() function:

<?php 
$args = array(
    'post_type' => 'post',
    'category_name' => 'featured'
);
$the_query = new WP_Query($args);
?>

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

Give that a try and that should take care of it.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I had this exact same issue and I thought I was going to have to write a new forum post about it.

Then I looked at my category name.

I too had it set to featured but the actual name that of the category that I had was features.

I expect by now you got the problem sorted but I was able to look at my categories and compare the 2. The titles will now show up and I'm now up to date. So just make sure your category names match up in Admin area and in your code.

<?php 
$args = array(
    'post_type' => 'post',
    'category_name' => 'features'
);
$the_query = new WP_Query($args);
?>