【发布时间】:2021-07-10 06:17:43
【问题描述】:
我在自定义分类“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()。但这在那个循环中也不起作用。
【问题讨论】:
-
您需要相应地为术语 ID 加上前缀,请参阅advancedcustomfields.com/resources/get_field/#examples,“从不同对象获取值”部分
标签: php wordpress loops taxonomy