Wordpress 使用 acf 显示分类法
Wordpress show taxonomy with acf
我无法在 WordPress 中使用 acf(select 多个)获取分类名称。
$categories_user = get_field('product__services', $company_id);
当我 var_dump($categories_user)
它输出:
array(2) {
[0]=> object(stdClass)#3816 (10) {
["term_id"]=> int(28)
["name"]=> string(17) "sous category 2-4"
["slug"]=> string(17) "sous-category-2-4"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(28)
["taxonomy"]=> string(11) "project_cat"
["description"]=> string(0) ""
["parent"]=> int(25)
["count"]=> int(2)
["filter"]=> string(3) "raw"
}
[1]=> object(stdClass)#3818 (10) {
["term_id"]=> int(34)
["name"]=> string(13) "Ywz categorie"
["slug"]=> string(13) "ywz-categorie"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(34)
["taxonomy"]=> string(11) "project_cat"
["description"]=> string(0) ""
["parent"]=> int(0)
["count"]=> int(0)
["filter"]=> string(3) "raw"
}
}
您拥有数据...您只需使用标准 foreach
循环显示它:
foreach ( $categories_user as $cat ) {
echo $cat->name;
}
我无法在 WordPress 中使用 acf(select 多个)获取分类名称。
$categories_user = get_field('product__services', $company_id);
当我 var_dump($categories_user)
它输出:
array(2) {
[0]=> object(stdClass)#3816 (10) {
["term_id"]=> int(28)
["name"]=> string(17) "sous category 2-4"
["slug"]=> string(17) "sous-category-2-4"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(28)
["taxonomy"]=> string(11) "project_cat"
["description"]=> string(0) ""
["parent"]=> int(25)
["count"]=> int(2)
["filter"]=> string(3) "raw"
}
[1]=> object(stdClass)#3818 (10) {
["term_id"]=> int(34)
["name"]=> string(13) "Ywz categorie"
["slug"]=> string(13) "ywz-categorie"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(34)
["taxonomy"]=> string(11) "project_cat"
["description"]=> string(0) ""
["parent"]=> int(0)
["count"]=> int(0)
["filter"]=> string(3) "raw"
}
}
您拥有数据...您只需使用标准 foreach
循环显示它:
foreach ( $categories_user as $cat ) {
echo $cat->name;
}