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:

    $terms = get_field('taxonomy_field_name', 123); //123 is the numerical post id identifier
    if( $terms ): ?>
    	<?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; ?>
    <?php endif; ?>