Support

Account

Home Forums General Issues Post Object Reply To: Post Object

  • It could have something to do with where you’re code is. Is it in a template file?

    The best suggestion I can give without understanding where you’re using this is to add

    
    global $post;
    

    like this

    
    $post_object = get_field('location');
    
    if( $post_object ): 
    
    	// override $post
            global $post;
    	$post = $post_object;
    	setup_postdata( $post ); 
            
    	?>
        <div>
            	<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        	<span>Post Object Custom Field: <?php the_field('test'); ?></span>
        </div>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif;