获取术语自定义字段


WordPress | Get term custom field

如果我在术语主题上有自定义字段,它看起来像这样:

<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$myimage = get_field('image', $taxonomy . '_' . $term_id);?>
<?php echo $myimage; ?>

我想在条款帖子上显示"图像"自定义文件,我的意思是任何使用条款X的帖子都会得到X的"图像"。

我该怎么做?

您需要使用自定义字段的名称更改custom-field

像这样<?php echo get_post_meta($post->ID, 'term-theme', true); ?>

你可以从这个WordPress代码页获得更多信息。