<?php $terms = wp_get_post_terms($post->ID,'category');
foreach ($terms as $term) {
$termcomp = $term->taxonomy . '_' . $term->term_id; } ?>
<?php the_field('tagline' , $termcomp); ?>
How Can I use this code on wordpress without it echoing 6 times, because I have 6 posts inside that category..
Full page template is there, the foreach is also at the bottom, this one works fine and only outputs once as needed.
Using Advanced Custom Fields, you can get the field for a category taxonomy custom field using the
get_field('field', 'category_'.$cat_id)
, orthe_field()
if you want to echo the results automatically. In your case, you first need to determine the current category id, and then callthe_field()
using it for your desired field name,tagline
. This should be loaded outside of theLoop
: