0

I've created a custom Taxonomy for a Custom Post Type, and created five or so terms within the taxonomy.

I've created a single image upload and assigned it to the custom taxonomy, and uploaded images for each term.

I can't for the life of me figure out how to get the image to display. I've var_dumped the term but there's nothing in there about the image?

Any help much appreciated!

WP version: 3.4.2 ACF version: 3.5.3.1

3

As per the plugin documentation:

The second parameter needed is a string in the format “$type_$id”.

// get value from a taxonomy (taxonomy = "category", id = 3)
$value = get_field('field_name', 'category_3');

// get value from a taxonomy (taxonomy = "events", id = 76)
$value = get_field('field_name', 'events_76');
0

The code of raison's answer didn't worked for me...

My code to get taxonomy name and term id in automatic way is like that:

$taxonomy = get_taxonomy( $taxonomy );
$taxonomy_name = $taxonomy->name;
$term_id = get_queried_object()->term_id;
$image_ids = get_field('your acf field name here', $taxonomy_name . '_' . $term_id , false or true or empty or string inside '' -  Depending on your field type);
0

Exactly as brasofilo said but if you may need to generate the taxonomy name and ID and in that instance the following code will help:

$taxonomy = $category->taxonomy;
$term_id = $category->term_id; 

$image =  wp_get_attachment_image_src(get_field('thumbnail', $taxonomy . '_' . $term_id), 'shop_catalog');

if ( $image )
  echo '<img src="' . $image[0] . '" alt="" />';

This is for an example of a custom query ($category) and for an Image ID. Hope that helps expand upon the other question.

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.