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 trialRobert Mylne
13,708 PointsWordPress Work Page
I am following along with the WordPress Track: Stage 3 WordPress Theme Functions Displaying Custom Posts and Fields in a Template
Though when I try and pull the work posts it ends up pulling the blog posts still.
Here is my code (btw I am using 'portfolio' instead of work):
<?php
/*
Template Name: Portfolio Page
*/
get_header(); ?>
<p>This is the portfolio</p>
<?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(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<hr>
<?php endwhile; else: ?>
<p>There are no posts or pages</p>
<?php endif; ?>
<?php get_footer(); ?>
2 Answers
Andrew Shook
31,709 PointsRobert Mylne, I believe your $args array is the problem. It's suppose to be "post_type" not "post-type". Check your code and see if that error is in it or just a typo in your post. You can check the documentation here.
Also, just a rule of thumb, in php you almost never use a dash. Words are almost alway separated with an underscore
Robert Mylne
13,708 PointsThat fixed it. Thanks for that.
Andrew Shook
31,709 PointsNo probelm
Sally Gradle
24,694 PointsSally Gradle
24,694 PointsI had the same problem. Thanks!