从 Wordpress 术语中获取自定义字段
Get custom field from Wordpress term
我对自定义分类法进行了简单循环 '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);
}
我对自定义分类法进行了简单循环 '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);
}