Home › Forums › General Issues › Related Posts by Taxonomy › Reply To: Related Posts by Taxonomy
Hi @leanda,
Thanks for the post.
The above code should list the Taxonomy terms, but if you are calling the Tax field outside the main posts loop, you might need to add a second parameter to the get_field() function and this should be a string containing the post->ID that the field is referenced in.
Your overall snippet should then look like so:
<?php
$terms = get_field('taxonomy_field_name', 123); //123 is the numerical post id identifier
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.