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 How to Build a WordPress Theme WordPress Theme Functions Displaying Custom Posts and Fields in a Template

Getting Wrong Kind Of Post

Hey everyone,

I'm having problems with the query posts. I'm getting the normal posts and not the work project posts. Here is part of my work.php. Can anyone help?

    <?php
    $args = array(
        'post-type' => 'work'
    );

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

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

    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    <?php the_field( 'description' ); ?>
    <hr>

<?php endwhile; else: ?>

    <p>There are no posts or pages here. :)</p>

<?php endif; ?>
    ```

3 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi!

Do you have this at the top of your code:

<?php 

/*

    Template Name: Work Page

*/


get_header(); ?>

And when you edit the Work page from you admin area have selected the Work Page template from template dropdown?

I did all of those things and even copy/pasted the code above and it's still displaying the wrong posts. I'm not really sure what it is. It might be a small typo or something. Here's my full work.php page:

<?php 

/*

    Template Name: Work Page

*/


get_header(); ?>

<p>This is the work.php file.</p>

<?php
    $args = array(
        'post-type' => 'work'
    );

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

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

    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    <?php the_field( 'description' ); ?>
    <hr>

<?php endwhile; else: ?>

    <p>There are no posts or pages here. :)</p>

<?php endif; ?>

<?php get_footer(); ?>

Oh I was right. I just noticed it. I made a typo where it was suppose to be _ instead of -.