Advanced Custom Fields – Code to Display Blog Post in a Template Using a Function

<div style=”margin-left:50px; padding-left:50px; width:400px;”>

<?php

$post_object = get_field(‘blog1’);

if( $post_object ):

// override $post
$post = $post_object;
setup_postdata( $post );

?>
<div>
<h3><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a>

<?php the_post_thumbnail( ‘medium’ ); ?> </h3>

<?php echo wp_trim_words( get_the_content(), 60 );?>

</div>
<?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>

</div>

Published

Leave a comment

Your email address will not be published. Required fields are marked *