Search code examples
wordpressloopsadvanced-custom-fieldscustom-post-type

How to show all categories of custom post type with category thumbnail which is created by ACF in a loop?


How to show all categories of custom post type with category thumbnail which is created by ACF in a loop?

    <div class="row">
        <div class="col-lg-2 col-md-3">
            <div class="c-brintons-box">
                <div class="c-brintons-img">
                    <img src="img/brintons-3.jpg" alt="">
                </div>
                <h3>Royal Marquis</h3>
                <a href="#"></a>
            </div>
        </div>
    </div>
</div>```

Solution

  • $terms = get_terms( array(
       'taxonomy' => 'taxonomy_slug', // enter your taxonomy slug here
       'hide_empty' => false,
    ) );
    foreach($terms as $term) {
        $img = get_field('img_field_name', $term); // enter your img field name here
        $term_name = $term->name;
    
        // TODO: Your HTML code here
    }