Skip to content
Advertisement

Getting Post Thumbnail to show for Single Post Obect (WP + ACF)

I am having a hard time getting the WordPress thumbnail to show up when I am using Advanced Custom Fields Pro Post Object.

My goal is to have the user select a single featured post to show up after the 6th post on the blog page.

This is my code (which is pretty much directly from ACF documentation):

JavaScript

This returns the correct title but the wrong featured image (from the post above).

The code above is called inside the loop on index.php inside the featured template part.

JavaScript

I have tried the other code examples on the documentation page but those return all of my posts (again with only one thumbnail, not the correct thumbnail per post).

I am not sure where to go from here.

Anyone who can help would be greatly appreciated!

Advertisement

Answer

Since this is not in the loop context, the function does not find the correct post object set up to take the ID from. Use get_the_post_thumbnail instead, that takes the post id as parameter.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement