Hi,
I try to get taxonomy values of my ACF color picker but my fucntion returns empty.
Do yo know where i am wfong please ?
Taxonomy slug = portfoliocategories
Terms slug = sport, culture, others
Acf slug = couleur
add_shortcode( 'acf_colour' , 'get_colour');
function get_colour( $atts ) {
$queried_object = get_queried_object();
$term_id = $queried_object->ID;
$terms = wp_get_post_terms($term_id ,'portfoliocategories');
foreach ( $terms as $term ) {
$colour= get_field('couleur', $term->taxonomy . '_' .$term->term_id );
print_r ($colour);
}
return $colour ;
}
wp_get_post_terms requires a post ID, it appears you’re trying to use the term_ID.
You can get your taxonomy values:
<?php if( $portfoliocategories = get_terms( array( 'taxonomy' => 'portfoliocategories' ) ) ) :
foreach( $portfoliocategories as $category ) :
$couleur = get_field('couleur', 'term_' .$category->term_id );?>
<?php echo $category->name.' has couleur: '.$couleur.'<br/>'; ?>
<?php endforeach;
endif;
?>
Code untested. Also worth looking at this page on Loading from a specific term
Thanks but it seems my code is correct finally.
Can you share your solution? It may help others going forward.
My code is working, the problem was in wordpress shortcode