2017-03-24 97 views

回答

0

如果在選項表中保存的自定義字段,可以這樣獲取:

$options = get_option('category_info'); 
echo $options[$taxonomy->term_id]; 

或者,如果你正在使用ACF,您可以retreive這樣的自定義字段:

<?php 

// load all 'category' terms for the post 
$terms = get_the_terms(get_the_ID(), 'category'); 


// we will use the first term to load ACF data from 
if(!empty($terms)) { 

    $term = array_pop($terms); 

    $custom_field = get_field('category_image', $term); 

    // do something with $custom_field 
} 

?> 
+0

我不確定。我用ACF插件創建了自定義字段。我嘗試了你的建議,但它不起作用。 – Justinas

+0

如果使用ACF創建它,您可以像這樣檢索它: '<?php the_field('category_info','news'); ?> – Litzo

+0

這不起作用。我嘗試在後循環中顯示此自定義字段的值 - 因此,如果該帖子具有選定的類別,那麼將顯示該自定義分類(該類別)的該自定義字段。 – Justinas

相關問題