Support

Account

Home Forums General Issues Show taxonomy image on custom post Reply To: Show taxonomy image on custom post

  • The first thing that you need to do is to get the terms that the post is in.

    
    $post_id = $post->ID;
    $taxonomy = 'custom-category';
    $args = array('fields' => 'ids');
    $terms = get_post_terms($post_id, $taxonomy, $args);
    

    $terms will hold an array term ids that the post is in. For more information on this see https://codex.wordpress.org/Function_Reference/wp_get_post_terms

    Once you have a list of terms you can get the images from those terms. In the below I am using “image_field” for the name of your image field.

    
    for (i=0; i<count($terms), i++) {
        $term_post_id = $taxonomy.'_'.$terms[i];
        $image_url = get_field('image_field', $term_post_id);
        if ($image_url) {
            // your code for showing the image here
        }
    }
    

    For more about getting values in acf from things like taxonomy terms see the Get a value from other places section on this page: http://www.advancedcustomfields.com/resources/get_field/