1
votes

I have a taxonomy named country. I used acf to add 2 new custom fields as seen in the pictureenter image description here

But when i try to access those fields, i cannot find them. All i have are

"country": {
  "term_id": 1,
  "name": "aaaa",
  "slug": "aaaa",
  "term_group": 0,
  "term_taxonomy_id": 1,
  "taxonomy": "country",
  "description": "",
  "parent": 0,
  "count": 0,
  "filter": "raw"
},

I tried doing this but I don't get the values.

$terms = get_terms( array(
                          'taxonomy' => 'country',
                          'hide_empty' => false,  ) );

 $output = '';
 foreach($terms as $term){
    //$output .=   $term->name . '-';
    $output .= get_field( 'flag', 'country'.'_'.$term->term_id );
  }

What am i doing wrong? Thank You

1

1 Answers

1
votes

To get an acf field, you are supposed to use get_field() To get a taxonomy field use this syntax

$variable = get_field('fields_slug', $term);

in your case, if you are

$country_flag = get_field('flag', $term);

$country_currency = get_field('currency', $term);

P.S. change flag, currency with the slug you have set while creating those fields and $term is an pure taxonomy object and not id or slug.