Get value in custom field with taxonomy [closed]

I have custom field my_cf for Taxonomy/Term. How can I get and output value with custom field for taxonomy/term?

I’ve tried using:

$variable = get_field('my_cf', 'basic'); 
  echo $variable; 

where basic – name for my taxonomy. But this doesn’t work.

Any suggestions?

3 s
3

I can’t really explain it any better than the ACF documentation page I posted in the comments:

All the API functions can be used with a taxonomy term, however, a second parameter is required to target the term ID. This is similar to passing through a post_id to target a specific post object.

The $post_id needed is a string containing the taxonomy name + the term ID in this format: $TaxonomyName_$TermID

So if your custom field is my_cf, and your taxonomy name is basic (not term name) and the term ID within your taxonomy is 42, then you need:

$variable = get_field( 'my_cf', 'basic_42' );

Leave a Comment