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.
http://bit.ly/1autG0d
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; ?>
Hi @overachiever
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.
Hi @overachiever
What did you see in your debugging?
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.
Hi @overachiever
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