Support

Account

Home Forums General Issues Trouble getting post object data to appear in front end

Solving

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.

    http://bit.ly/1autG0d

    • Nuro

    • September 18, 2013 at 10:59 am

    Can you post your code?

  • 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; ?>

    • Elliot

    • September 18, 2013 at 12:57 pm

    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.

    • Elliot

    • September 19, 2013 at 1:38 pm

    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.

    • Elliot

    • September 19, 2013 at 2:04 pm

    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.

    • Elliot

    • September 21, 2013 at 2:19 pm

    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

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.