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 How to Make a Website with WordPress Custom Post Types and Fields in WordPress Custom Post Type Templates

Zen Zen
Zen Zen
1,505 Points

Stage 4 - Custom Post Types and Fields in WordPress

I followed the steps exactly and the data isn't displaying:


How can I troubleshoot this to work out what the hell is going wrong?

Can you give some more details as to what you're trying to do? What is the step requesting you to do?

Zen Zen
Zen Zen
1,505 Points

So its to do with the custom post types http://teamtreehouse.com/library/custom-post-types-and-fields-quiz-2 I think thats the link or https://teamtreehouse.com/forum/content:4812 but basically I add the 4 images and they are not displaying :( I don't know how to troubleshoot it to resolve the issue :(

1 Answer

So if I understand correctly, you've already installed the the Advanced Custom Fields plugin that is mentioned near the beginning of the course and set up your custom fields to appear in certain posts. IF not, you'll definitely want to install this plugin and learn how to use it to your advantage. The main issue I believe you're having is dealing with how WordPress does not have a native functionality custom fields; you need to add the field calls in your template. I grab mine by using something like $myNewImage = get_field('special_image_1') where "special_image_1" is the slug for that custom field. SO to have an image display I would do, <?php echo "<<< html code for img src='".get_template_directory_uri()."/_images/".$myNewImage.".jpg' width='100%'>"; ?> That is how you call a custom field and display it as an image, if that's what the content is. I hope I understood your intent correctly, let me know if it's not exactly what you're trying to achieve.

Zen Zen
Zen Zen
1,505 Points

So I'm following the course and yeah I've installed the plugins, and made art custom posts like suggested. Here is what one looks like


I checked wp uploads and that is ok no permission issues or anything, I don't know why is it not working? :(

Antonio Carito 1,860 less than a minute ago

Okay so if you're doing it that way, which seems like everything is good, then you'll need to go into your template file where you want this post ti show and put in the codes I mentioned before:

$myArt = get_field('art_1');

'art_1' is a field name that I just made up, for you it would be whatever the slug is for the custom field.

Then use the html code for img src, where, src='$myArt'


<?php echo "<<< img src='".get_template_directory_uri()."/_images/".$myArt.".jpg' width='100%'/>"; ?>