Home › Forums › General Issues › Trouble getting post object data to appear in front end
Everything appears okay in the back end, the data is inputted and the code is in the loop, but nothing appears in the front end.
adlinks is the field label.
<?php
$post_object = get_field(‘post_object’);
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<div>
<h3>“><?php the_title(); ?></h3>
<span>Post Object Custom Field: <?php the_field(‘adlinks’); ?></span>
</div>
<?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Can you debug the $post_object value?
$post_object = get_field('post_object');
echo '<pre>';
print_r( $post_object );
echo '</pre>';
die;
Next, Try the code without using the setup_postdata function:
<?php
$post_object = get_field('post_object');
if( $post_object ): ?>
<div>
<h3><?php echo get_the_title( $post_object->ID ); ?></h3>
<span>Post Object Custom Field: <?php the_field('adlinks', $post_object->ID ); ?></span>
</div>
<?php endif; ?>
Hello, I tried my best to follow your instructions, but I still could not get the custom field values to appear in the front end.
I have a separate custom field: ‘Text area’ that is working fine on the site.
Just text markup… Would you mind repeating the instructions step by step because I kind of get confused when “debug” is thrown out there.
Thanks.
Debug means to test the value. eg:
$post_object = get_field('post_object');
echo '<pre>';
print_r( $post_object );
echo '</pre>';
die;
Hey Elliot, when I use that code in my backend, my site shuts down with an error.
Perhaps you could post the error you see?
Perhaps you could also research into debugging techniques to understand what it is your nee to achieve.
Thanks
E
The topic ‘Trouble getting post object data to appear in front end’ is closed to new replies.
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.