skip to Main Content

I created a custom taxonomy, I added 2 ACF fields to it, in the back end everything works great. But in the front end I cannot fetch the ACF values.

$context['bankingoptions'] = wp_get_post_terms($post->ID, 'review_banking', array());
var_dump($context['bankingoptions']);

Will display below, notice there are no ACF values, there are 2: link(Page Link), icon(image)

array (size=3)
  0 => 
    object(WP_Term)[2220]
      public 'term_id' => int 73
      public 'name' => string 'Bitcoin' (length=7)
      public 'slug' => string 'bitcoin' (length=7)
      public 'term_group' => int 0
      public 'term_taxonomy_id' => int 73
      public 'taxonomy' => string 'review_banking' (length=14)
      public 'description' => string '' (length=0)
      public 'parent' => int 0
      public 'count' => int 1
      public 'filter' => string 'raw' (length=3)
  1 => 
    object(WP_Term)[2222]
      public 'term_id' => int 74
      public 'name' => string 'Mastercard' (length=10)
      public 'slug' => string 'mastercard' (length=10)
      public 'term_group' => int 0
      public 'term_taxonomy_id' => int 74
      public 'taxonomy' => string 'review_banking' (length=14)
      public 'description' => string '' (length=0)
      public 'parent' => int 0
      public 'count' => int 1
      public 'filter' => string 'raw' (length=3)

2

Answers


  1. Chosen as BEST ANSWER

    @disinfor, your first response is the answer, this gets my data

    $arr = wp_get_post_terms($post->ID, 'review_banking', array());
    foreach ($arr as $value) {
        $icon = get_field('icon', $value);
        $link = get_field('link', $value);
        var_dump($icon);
        var_dump($link);
    }
    

  2. If you accessing ACF fields anywhere out of taxonomy pages then your code will be as below

    Syntax –

    $field = get_field('field_name', $taxonomy_slug . '_' . $taxonomy_term_id);
    

    Eg. –

    $field = get_field('field_name', 'review_banking_123');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search