Home › Forums › General Issues › Taxonomy Term Image Field for Product Categories
I have a custom post type of products which has a taxonomy of product categories.
I have added an ACF image field to this.
I want to be able to output a title, description and image for each category on archive-products.php (which is my template for /products/)
I have been using a get_categories query as below for the standard output, I have tried to include the_field for the image but I cannot get it to display, how can I do it? I’ve read the documentation but can’t get it going.
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
}
?>
Hi @maxis,
Well, to get ACF values associated with a particular term, you have to pass an extra argument to the_field(...)
or get_field(...)
method to target the term ID. This argument can either be a term object or a term string as explained in the docs. The following code should work for you:
foreach($categories as $category):
...
$image = get_image('image_field_name', $category);
echo '<img src="'.$image['url'].'" alt="'.$image['alt'].'" />';
endforeach;
hi i need to get the category
and title from the tasxonomy term
plz help me to find the solution
here is my code
<?php
$terms = get_field(‘taxonomy_field_name’);
if( $terms ): ?>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
“>View all ‘<?php echo $term->name; ?>’ posts
<?php endforeach; ?>
<?php endif; ?>
Hi @harikrishnan-1infogmail-com
I believe I’ve answered your question here: https://support.advancedcustomfields.com/forums/topic/taxonomy-field-get-the-category-image-and-name-from-selected-multiple-category/. Could you please check it out?
Thanks 🙂
The topic ‘Taxonomy Term Image Field for Product Categories’ is closed to new replies.
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.