Display post_object content using Advanced Custom Fields plugin

The code doesn’t seem syntactical wrong in the first place. What kind of field type are you using? Relationship?

Also why are you overriding $post_object and where does it come from in the first place? That part of the code is missing.

To get the field which is attached to the current post (inside the current loop / global $post object you are viewing) you simply have to use get_field('testimonial') without the ID param.

If you want to get the field attached to another post_object did you check that $post_object->ID contains an valid post_id right before the first line you posted?

Edited according to new info:

Is this a post object field with the ‘multiple’ option enabled? The docs (http://www.advancedcustomfields.com/resources/field-types/post-object/) say that this fields only returns an array of post objects when the multiple option is enabled otherwise it will only return a single post object. This would mean that you won’t need the foreach-loop in your code. In that case you should use it like this:

<?php $featured_testimonial = get_field('testimonial', $post_object->ID); ?>
            <a href="https://wordpress.stackexchange.com/questions/97060/<?php echo get_permalink($featured_testimonial->ID); ?>">
                <p class="descr"><?php echo get_the_title($featured_testimonial->ID) ?></p>
            </a> 

Leave a Comment