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 WordPress Theme Development Custom Post Type Templates in WordPress The Portfolio Homepage

kelley riley
kelley riley
3,159 Points

My query loop is not pulling my custom post types that I created using CPT UI. They don't display on any custom page.

I'm not sure what I'm missing. I've looked at outside sources but cannot seem to find an answer. On my custom portfolio page, my custom post type, which is a portfolio piece, does not display.

I don't get any errors, the page simple just loads blank.

    Template Name: Portfolio Page

<?php get_header(); ?>
   <section class="row">
      <div class="small-12 columns text-center">
        <div class="leader">
         <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
          <h1><?php the_title(); ?></h1> 
           <?php the_content(); ?>
        <?php endwhile; endif ; ?>
    $args = array( 'post_type' => 'entry', 'posts_per_page' => 10 );
    $the_query = new WP_Query( $args ); 
<section class="row no-max pad">
    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <div class="small-6 medium-4 large-3 columns grid-item">
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
    <?php  ?>
    <?php endwhile; endif; wp_reset_postdata(); ?>
<?php get_footer(); ?

In the code you pasted, there is a missing ">" at the very end. There is also an unnecessary "<?php ?>" above your second endwhile & endif statements that could be removed. However, if you are seeing a simple blank page these issues are not the reason!

Your code worked fine for me. That said I think the issue is coming from either not having the correct slug for the custom post type you want to display, or not having your portfolio page set to the "Portfolio Page" template.

1st possible issue: in this line:

$args = array( 'post_type' => 'entry', 'posts_per_page' => 10 );

the string: 'entry' has to match the slug you've set in the custom post type you want to display. To make sure they match, go into your WP admin dashboard and click on CPT UI then click on the Edit Post Types tab. Make sure the post type you want to check is selected in the drop down menu immediately below the tabs and look at what is in the "Post Type Slug" field. Whatever is in that field should be put in the above line of code in place of 'entry'. If 'entry' is the correct slug then maybe it is issue number 2.

2nd possible issue: From the WP admin dashboard click on pages, then click on your portfolio page. On the right hand side there will be a dropdown with "Template" above it. Make sure that is set to "Portfolio Page" and the updates are saved.

If neither of these are the issue let me know and I'll try to think of what else could be causing problems!