0

Using ACF i've added a custom image field to a particular set of custom post tags. The problem I have is that I cannot get the images to display. Yes, I have added an image to the tag and updated.

        $term_id = 26;
        $taxonomy_name = 'tags';
        $termchildren = get_term_children( $term_id, $taxonomy_name );

        foreach ( $termchildren as $child ) {

            $term = get_term_by( 'id', $child, $taxonomy_name );
            $tag_image = get_field('tag_image');
            echo '<a href="?categories=' . $term->slug . '">'. $term->name . '</a>';
            echo $tag_image; //this bit doesn't work :(


        }
0

As per the ACF documentation, you must pass either the term and term ID or the term object to the get_fields() function for a taxonomy.

So in your case, you would replace $tag_image = get_field('tag_image'); with:

$tag_image = get_field('tag_image', $term);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.