2017-03-24 100 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

相关问题