Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,109 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,109 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,109 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:)