ACF Post object on a Taxonomy Template

Getting the post object is easy on a page, but what if you want to put it on a taxonomy template? Add the term to the get_feild and voila!

<?php
	// which term?
	$obj = get_queried_object();
	// which field?
	$post_object = get_field('link_to_featured_project', $obj);
	
	if( $post_object ): 

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

	?>
    <div class="featured-post-link">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div><!-- featured post link -->
    <?php wp_reset_postdata(); ?>
	<?php endif; ?>

 

Leave a Reply

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

69 − = 60