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

PHP How to Build a WordPress Theme WordPress Theme Functions Displaying Custom Posts and Fields in a Template

Where do you add a WORK.PHP post?

In Displaying Custom Posts and Fields in a Template where do you add in the work.php posts such as " Dr. Wattz" - I couldn't get past this point weeks ago and no one responded. I swear there is a missing step in this course. I have no idea where these descriptions could live. HELEEEEEEEELLLPP!

Cristian Cristea
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Cristian Cristea
Front End Web Development Techdegree Graduate 36,165 Points

I have the same problem, when did he wrote the posts and custom fields??? i got the code and page setup right but got no content....custom posts and custom fields??????

1 Answer

Kevin Korte
Kevin Korte
28,148 Points

There are multiple players at play here.

  • Make sure you have your custom post type set up...in this case it's likely called "work".
  • Make sure you have your custom fields set up, and assign those fields the the CPT "work"
  • Create your post and fill in your fields in the WP admin dashboard, just like you would a regular post
  • Make sure you're calling the right template. Follow these steps if neeeded: http://codex.wordpress.org/Page_Templates
  • Make sure you're running your post query correctly. You'll want to run a new WP_Query and if your post type name is "work", than you want to pass the argument post_type => work to the new WP_Query.
  • Inside of the loop, make sure you are calling your fields correctly. The default WP functions like <?php the_title();?> and <?php the_content();?> will still work. Than depending on the custom fields you set up, and the names you give them, you will call them in your work.php template following the API that the Advance Custom Fields Docs give you. Often times you'll use something like <?php the_field( 'name-of-field' );?> to retrieve the field.

If you follow those steps, you should see your custom posts and custom fields show up on your custom template.