Answers for "acf single post object"

PHP
0

acf post object

<?php

// DISPLAY CONTENT FOR SINGLE POST OBJECT

$post_object = get_field('post_object');

if( $post_object ): 

	// override $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('field_name'); ?></span>
    </div>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Posted by: Guest on April-29-2020
0

post object

<?php
$featured_post = get_field('featured_post');
if( $featured_post ): ?>
    <h3><?php echo esc_html( $featured_post->post_title ); ?></h3>
<?php endif; ?>
Posted by: Guest on July-08-2020

Browse Popular Code Answers by Language