我无法在前端打印所选类别 我的后端代码是
array(
'name' => 'Test Taxonomy Multicheck',
'desc' => 'Description Goes Here',
'id' => 'wiki_test_taxonomy_multicheck',
'taxonomy' => 'category', //Enter Taxonomy Slug
'type' => 'taxonomy_multicheck',
// Optional :
'text' => array(
'no_terms_text' => 'Sorry, no terms could be found.' // Change default text. Default: "No terms"
),
)
我的前端代码是
<?php
$tax_chec = get_post_meta(get_the_ID(),'wiki_test_taxonomy_multicheck',true);
echo $tax_chec;
?>
答案 0 :(得分:1)
实际上,CMB2分类学多重检查表现为原生WordPress分类小部件 - 它不是您认为的自定义字段。所以,如果你在wiki_test_taxonomy_multicheck&#34; custom&#34;字段将在“类别”窗口小部件中选择相同的值。要检索所选值,请使用wp_get_post_terms
(参考:https://codex.wordpress.org/Function_Reference/wp_get_post_terms)
$terms = wp_get_post_terms($post->ID, 'category', array("fields" => "all"));
foreach($terms as $term) {
echo $term->name;
}