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

Charles Arciniega
Charles Arciniega
2,099 Points

images for custom post types

Hello,

I'm working through Zac's how to build a wordpress theme and have run into a problem. I had no trouble creating a custom post type for "work" and then had no problem creating custom fields for it as described in the video.

My page generates "work" posts dynamically but I'm not able to call the field associated with the project image.

for example. If i use <?php the_field( 'description' ); ?> then my template will generate the description assigned to any particular "work" post. However, if i use <?php the_field( 'homepage_slider_image' ); ?> as my src value, then no image appears.

If i add alt="Problem" to the image tag, then the alternate text shows up instead of the project image.

There are no typos in the code or ACF, and the fields are linked to the work custom post type so I'm really stumped as to why I'm having this problem.

Any help would be greatly appreciated =) thanks.

I did the course and it worked OK for me, this is copied/pasted from my content-work.php: <img src="<?php the_field('homepage_slider_image'); ?>">

Perhaps if you posted the code you are using we could take a look at it.

Sorry, my code disappeared and I can't edit the post, here it is:

<img src="<?php the_field('homepage_slider_image'); ?>">
Charles Arciniega
Charles Arciniega
2,099 Points

Thanks a lot for the help =) sadly I was using the same code just with this small adjustment

<img src="<?php the_field('homepage_slider_image'); ?>" alt="Problem">

I mean I followed the video exactly and have a lot of experience with ruby, html, and css so I understand whats happening behind the scenes and why the code works. I'm just surprised it doesn't work in my particular situation. Made a post because I thought maybe someone else was having the same problem.

Charles Arciniega
Charles Arciniega
2,099 Points

quick update: Got it to work by changing the custom field's name. I don't know why but 'homepage_slider_image' simply didn't work for me. If I change it back to 'homepage_slider_image' the image does not appear. But I got it to work =)

You've probably already thought of this, but how about trying a static image in the src attribute as a test, and using php echo to output the results of the_field to the page? Between those two things you might find the issue.

Our posts crossed... Nice one!

Charles Arciniega
Charles Arciniega
2,099 Points

I did try that! as well as get_field('custom_field');

Looked at ACF documentation. It's weird but the problem was just the naming for me haha. Thanks for the help!

I hope the suggestions in this post helps someone if they run into the same problem.

3 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Glad you got everything resolved. Thanks for helping out Tim

jack hamilton
jack hamilton
5,609 Points

I was also running into this problem and none of the answers above helped.

I found my answer by making sure the pictures you upload for "Home_screen_slider" are actually IN the images folder in your theme.

I was selecting them form another theme by accident and hence they were not showing up.

carriebarnett
carriebarnett
16,732 Points

So I am having the same issue noted previously here on this discussion. My images for the homepage_slider_image are not loading. I went back and double checked the custom fields video to make sure I had everything set up correctly. I double checked the code for the work.php file. I have an images folder inside my named theme folder with the project images. What am I missing? Did I miss something in a prior video about the images? There are no subfolders in the images folder. The descriptions, button color, and title portion of the code work. I did notice in the intro video that shows us the static webpage html, that the css folder has an images folder inside it? Could this have something to do with it? Stumped... could use some direction