我目前正在ACF中使用分类字段,目的是在前端打印类别名称。这样使用:
<?php $term = get_sub_field(\'category_selector\'); if( $term ): ?>
<span><?php echo $term->name; ?></span>
<?php endif; ?>
当前未显示任何内容,我已调试$term
不显示的类别ID3
, 但出于某种原因,我无法从中获得类别名称?如有任何建议,将不胜感激!我目前正在ACF中使用分类字段,目的是在前端打印类别名称。这样使用:
<?php $term = get_sub_field(\'category_selector\'); if( $term ): ?>
<span><?php echo $term->name; ?></span>
<?php endif; ?>
当前未显示任何内容,我已调试$term
不显示的类别ID3
, 但出于某种原因,我无法从中获得类别名称?如有任何建议,将不胜感激!假设3
是类别ID。。。
$term = get_sub_field(\'category_selector\');
if( $term ) {
foreach($term as $t) {
$t = get_category($t);
echo $t->name;
}
}
换句话说,看起来ACF只是存储ID,而不是整个对象,所以在访问名称、slug等之前,需要使用该ID获取类别对象。我阅读了codex的文档,但我不能像parent、childrens那样对get\\u categories()结果排序。我有以下三类:-Events - Music - Culture - Workshop - Tourism -Sport -Football -Rugby -Tennis 我希望输出为:Events, Music 我试过:echo $product
我目前正在ACF中使用分类字段,目的是在前端打印类别名称。这样使用:
<?php $term = get_sub_field(\'category_selector\'); if( $term ): ?>
<span><?php echo $term->name; ?></span>
<?php endif; ?>
当前未显示任何内容,我已调试$term
不显示的类别ID3
, 但出于某种原因,我无法从中获得类别名称?如有任何建议,将不胜感激!假设3
是类别ID。。。
$term = get_sub_field(\'category_selector\');
if( $term ) {
foreach($term as $t) {
$t = get_category($t);
echo $t->name;
}
}
换句话说,看起来ACF只是存储ID,而不是整个对象,所以在访问名称、slug等之前,需要使用该ID获取类别对象。我需要将自定义选项添加到wp_dropdown_categories. 现在,整个万维网世界还没有找到解决方案。。。因此,我在这里要求一个解决方案……因为我真的无法想象WordPress的开发人员没有考虑到这将永远不需要,对吗?