I've built a widget to show pages from a certain category in a dropdown menu. The page that's selected will show up on the homepage. This all works, except the Advanced Custom Fields (ACF) are all showing the same image. I think it's to do with $instance...

The code I'm using is:

    <div class="home-image-box">

    <?php $attachment_id = get_field('main_image');
    $size = "home-boxes";
    $image = wp_get_attachment_image_src( $attachment_id, $size );

    <a href="<?php echo get_permalink($instance['post_id']); ?>">
    <img class="headline" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" src="<?php echo $image[0]; ?>" />

    <p class="extra-text"><?php the_field('sub_title'); ?></p>

All the code works great on the individual pages - it's just when called by the widget that I get these issues. The title and permalink are using the normal Wordpress functions, and these work fine too.

Are there any ACF users here that can shed some light on this?


  • 2
    Are you referring to a "widget" (/wp-admin/widgets.php) or to an ACF meta box showing up in /wp-admin/post.php?post=POST_ID? In what theme template is this code happening? How are you re-using it?
    – brasofilo
    Commented May 5, 2013 at 20:57
  • To a widget. Here's the full code: pastebin.com/kgm3cL7v It's a custom built theme (if that's what you meant?).
    – Dave
    Commented May 5, 2013 at 22:07
  • Gah - I was looking too deeply into this... Passing postID as the second parameter works perfect.Thanks so much! Do you want to make this as an answer so I can accept it as solved?
    – Dave
    Commented May 5, 2013 at 23:17
  • 1
    Dave, when there are more than two commenteers, you have to address the other party like: @dalbaeb, so he/she receives a notification in the inbox.
    – brasofilo
    Commented May 6, 2013 at 18:26

1 Answer 1


Try passing the post ID as the second parameter:

the_field('sub_title', $instance['post_id']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.