I am very new to wordpress theme development and I have created a custom post and custom taxonomy . I have created a image acf on taxonomy now I want to show all the taxonomy term and their acf fields on front-page . I can get all term by using get_terms() function but I don't know how to get acf field of that taxonomy.
$terms = get_terms(array(
"taxonomy" => "categories",
"hide_empty" => false ));
foreach($terms as $term):
echo $term->name;
endforeach;
I want term name and image acf field of that term on front-page.php . Any advice will be helpful and thanks in advance.
CodePudding user response:
Please try this code
<?php
$terms = get_the_terms(get_the_ID(), "categories");
if (!empty($terms)): ?>
<ul>
<?php foreach ($terms as $term): ?>
<li >
<img src="<?php the_field("image_field_name", $term); ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php endif;
?>
For more details you can check this documentation.