2016-06-21 34 views
0

我沒能打印選定類別中的前端
我的後端代碼是如何打印CMB2字段類型?

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; 

     ?> 

回答

1

其實CMB2分類multicheck表現爲本地WordPress分類小工具 - 它不是您想象的自定義字段。因此,如果您在wiki_test_taxonomy_multicheck「自定義」字段中檢查某些內容,則會在類別小部件中選擇相同的值。要檢索選定的值使用wp_get_post_terms(ref: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; 
}