skip to Main Content

I’ve made a simple loop over a custom taxonomy ‘product_category’:

$args = array('hide_empty' => false, 'orderby' => 'term_group', 'parent' => false);
$terms = get_terms('product_categorie', $args);

foreach ($terms as $term) {
    echo "<a href=''>".$term->name."</a>";
}

I’ve added a custom field ‘webshop_url’ to the taxonomy. I’ve tried multiple solutions to print that custom field in my loop, but without luck.

I’ve tried these things in my foreach loop:

echo get_field('webshop_url', 'product_categorie', $term->term_id);

echo get_field('webshop_url', $term->term_id);

It doesn’t print anything.

I know it’s possible to use get_queried_object() on the taxonomy page itself. But that doesn’t work either in that loop.

2

Answers


  1. Try to pass term OBJECT

    echo get_field('webshop_url', $term);
    
    Login or Signup to reply.
  2. May you try like this:

    ACF Document

    $args = array('hide_empty' => false, 'orderby' => 'term_group', 'parent' => false);
    $terms = get_terms('product_categorie', $args);
    
    foreach( $terms as $term ) {
        $webshop_url = get_field('webshop_url', 'product_categorie'.'_'.$term->term_id);
        var_dump($webshop_url);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search