Support

Account

Home Forums ACF PRO ACF Taxonomy

Solving

ACF Taxonomy

  • Hey.

    Im trying to create a loop-item for my custom Taxonomy “product_categories” i’ve assigned 2 fields to it, name => “c_name”, image => “c_image”.

    Now when I im in my loop template, i’ve assigned those fields to the text and image but its not showing me anything. I’ve tried searching internet but haven’t got lucky. so posting here in the end.. im using ACF PRO.

    Do reply to my thread.

    Thank You.

  • And what are you using to build this loop template? Code? A page builder?

  • Sorry for not providing proper info..
    I’m using Elementor pro .. and using its loop template in theme builder.

  • In your loop template, use the get_field() function to retrieve the custom field values for each term in the “product_categories” taxonomy. Here is an example code snippet:

    <?php
    $terms = get_terms( array(
        'taxonomy' => 'product_categories',
        'hide_empty' => false,
    ) );
    
    foreach ( $terms as $term ) {
        $name = get_field( 'c_name', $term );
        $image = get_field( 'c_image', $term );
    
        if ( $name ) {
            echo '<h2>' . esc_html( $name ) . '</h2>';
        }
    
        if ( $image ) {
            echo wp_get_attachment_image( $image, 'thumbnail' );
        }
    }
    ?>

    This code snippet retrieves the “c_name” and “c_image” custom field values for each term in the “product_categories” taxonomy and displays them in the loop.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.