Wondering if anyone knows how to access a custom field from a custom-post category.
I have a font-awesome icon attached to each category and want to display it.
Currently displaying category name:
$categories = get_the_terms( $post->ID, 'domain_type' );
foreach( $categories as $category ) {
echo '<span class="btn btn-primary btn-sm">'.$category->name.'</span>' ;
}
But want to display icon but can’t get it working:
$categories = get_the_terms( $post->ID, 'domain_type' );
$icon = get_field('domain_icon');
foreach( $categories as $category ) {
echo '<i class="fa'.$icon.'"></i>' ;
}
Thanks in advance 🙂
Please see the “Getting values from other places” on this page https://www.advancedcustomfields.com/resources/get_field/. You need to supply the correct $post_id value that matches the category.
$categories = get_the_terms( $post->ID, 'domain_type' );
foreach( $categories as $category ) {
$icon = get_field('domain_icon', $term->taxonomy.'_'.$term->term_id);
echo '<i class="fa'.$icon.'"></i>' ;
}
Hello!
I ask from my ignorance, where does that code go? in the function.php?
thank you
regards!