Support » Plugin: Advanced Custom Fields » [Plugin: Advanced Custom Fields] Unable to get URL from post_object

  • I’m not sure what I’m doing wrong here. I have a field called “grid_thumbnail” and a “related_projects” post_object. I am able to display the title of the related post. I just don’t know how to get the Image URL of that related post. Suggestions?

    <?php foreach(get_field('related_projects') as $post_object): ?>
    
    <li>
    <img src="<?php echo get_field('grid_thumbnail'); ?>"><br />
    <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>
    </li>

    http://wordpress.org/extend/plugins/advanced-custom-fields/

Viewing 2 replies - 1 through 2 (of 2 total)
  • How can I get a specific image field src from a related post, is basically what I’m asking.

    For example:

    <img src="<?php echo get_field($post_object->grid_thumb); ?>">

    That doesn’t work. How can this be resolved?

    Hi estevancarlos,

    In case you or future googlers do not find this on the AFC forms

    Hi guys,

    Here’s some tips to get setup_postdata to work.
    1. when defining the foreach loop, the single item must be called $post.
    2. after the loop you need to use wp_reset_postdata(); to set the $post object back to normal.

    eg

    <?php foreach(get_field('related_post_items') as $post):
        setup_postdata($post); ?>
        <h2><?php the_title(); ?> - <?php the_field('something'); ?></h2>
    <?php endforeach; wp_reset_postdata(); ?>

    You can read more about it here: http://codex.wordpress.org/Function_Reference/setup_postdata

    best,
    Owen

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Advanced Custom Fields] Unable to get URL from post_object’ is closed to new replies.