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

Displaying Custom Posts and Fields in a Template

Hi everybody, I have watch the video several times and i still cant seem to pull the work post to the work page? I dont know what I am doing wrong:(<?php

/*

Template Name: Work Page

*/

get_header(); ?>

<p>This is the work.php Dee</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><?php the_title() ;?></h3>
<?php the_content(); ?>
<hr>

<?php endwhile; else: ?>

<p>There are no posts or pages here</p>

<?php endif; ?>

<?php get_footer(); ?>

12 Answers

Patricia Neale
Patricia Neale
9,256 Points

Hi Diane,

I was having the same problem until I realised that I had not actually set up any work posts! The video shows 4 posts (Stop Visual Pollution, Dr Watz, Smells Like Bakin', Shirts 4 Mike) but, as far as I can see, at no point have we been asked to create them. This is what is causng the confusion. Anyway, I just set up a couple of test work projects from the admin menu. I will do the same for testimonials. Hope this helps.

Winnie E Tibingana
Winnie E Tibingana
21,066 Points

Yes, adding test work projects works. Thanks Patricia.

Kevin Korte
Kevin Korte
28,148 Points

On your work page in your admin, where you can set the page title and context, in a box on the right of the screen, there is a dropdown for selecting a page template. There should be an option of Work Page now available. Select that, and than click the button to update the page.

Hi Kevin, yes I do have that selected.

Kevin Korte
Kevin Korte
28,148 Points

Okay, and do you have a custom post type set up called 'Work'? Are you using the Custom Post Type UI plugin?

Yes, I installed both plugins and I have a custom post type titled 'Work'

Matt Campbell
Matt Campbell
9,767 Points

I'm guessing nothing is coming up on the page at all or just one post? I'm not seeing any curly braces around your loop.

Actually the the content that I pasted on the page is showing along with the title, but no post. And curly braces are not included because the video did not instruct it.

Dose anyone know if there is compress folder that I can download to compare my code with?

Kevin Korte
Kevin Korte
28,148 Points

Your title says custom fields, but I do not see any custom fields in your code. What custom fields are you trying to show?

Displaying Custom Posts and Fields in a Template 7:08 is the title of the course that I am taking and having trouble with.

Thanks Patricia, I did try creating a work category but that still did nt work for me. I'll keep trying. Do you know if there's a completed project file we could download to compare our work to. That would save time:)

I found the completed project files they are in the Converting Static HTML into WordPress Templates course. Thanks Tree House your the Best:)