Advanced Custom Fields
[resolved] Post thumbnail output with Post Object (2 posts)

  1. gasurgaelach
    Posted 4 years ago #

    I am currently trying to create a 'Similar Posts' type section at the bottom of some of my posts. Would anyone be able to tell me how to add a featured image? At the minute, I'm using the details code:

    <?php foreach(get_field('lyrics_appears_on') as $post_object): ?>
    <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>
    <?php endforeach; ?>

    But the the various post thumbnail snippets don't seem to work. I'm guessing this is because they don't pull the post ID like the snippets above. Is there any way I can add an image to the code above? I've tried this, but it's just a stab in the dark..

    <?php wp_get_attachment_image( $post_object->ID, $thumbnail ); ?>

    Thank you! :)


  2. gasurgaelach
    Posted 4 years ago #

    Hi all, I didn't know of a cool wee WordPress function ( wp_get_attachment_thumb_url ), sorry for the post!

    Here's what I'm using:

    <img src="<?php echo wp_get_attachment_thumb_url(get_post_thumbnail_id($post_object->ID)); ?>" alt="<?php echo get_the_title($post_object->ID) ?>" />

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic