问题描述
我对自定义分类法“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>";
}
我在分类中添加了一个自定义字段“webshop_url”。我尝试了多种解决方案来在我的循环中打印该自定义字段,但没有运气。
我在 foreach 循环中尝试过这些东西:
echo get_field('webshop_url','product_categorie',$term->term_id);
echo get_field('webshop_url',$term->term_id);
它不打印任何东西。
我知道可以在分类页面本身上使用 get_queried_object()
。但这在那个循环中也不起作用。
解决方法
尝试传递术语 OBJECT
echo get_field('webshop_url',$term);
,
可以这样试试吗:
$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);
}