Home › Forums › Front-end Issues › Title for referenced Post Object not right › Reply To: Title for referenced Post Object not right
You already got the post_object, you dont need to setup_postdata and in some functions you have to pass the id as integer, not a function (get_field)…
So you can echo directly from the post_object, something like this:
<?php if( have_rows('cast') ): ?>
<ul class="events">
<?php while ( have_rows('cast') ) : the_row(); ?>
<li>
<?php $post_object = get_sub_field('choose_cast_members'); ?>
<?php if( $post_object ): ?>
<?php
$thumbid = get_post_thumbnail_id($post_object->ID);
$thumb = wp_get_attachment_image_src( $thumbid ), 'thumbnail' );
$url = $thumb['0'];
?>
<?php //$post = $post_object; setup_postdata( $post_object ); //dont need to setup_post_data ?>
<a href="<?php echo get_permalink($post_object->ID);//here ?>">
<img src="<?php echo $url; ?>" alt="<?php echo $post_object->post_title; //here ?>" />
</a>
<h3><?php echo $post_object->post_title; ?></h3>
<?php echo apply_filters('the_content', $post_object->post_content); ?>
<?php //wp_reset_postdata(); ?>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.