将自定义类别描述的值显示到单个帖子



我正在尝试提取我使用喷气引擎创建的自定义类别的描述值(类似于 ACF(。 不幸的是,JetEngine 无法选择这样做,这就是为什么我创建了自定义简码

/* function for programs category description */
function custom_desc_func() {
ob_start();
$terms = get_terms(
array(
'taxonomy'   => 'program-episode',
'hide_empty' => false,
)
);
if ( ! empty( $terms ) && is_array( $terms ) ) {
foreach ( $terms as $term ) {
$tid = $term->term_id;
}
?>
<span>
<?php echo get_term_meta(46, 'program-intro-description', true 
) ?>
</span>
<?php
}
return ob_get_clean();
}
add_shortcode('custom_desc', 'custom_desc_func');

/* 程序类别描述的功能结束 */

代码正在工作,但如您所见,我在代码 (46( 中手动添加类别 ID 号 - 如何使其更加动态?

例如

  1. "帖子 A 和帖子 B"在其中分配了"Cat A"。那么我希望"Cat A"的自定义描述出现在前端的两个帖子(A和B(上

请检查下面的代码并让我知道。

function custom_desc_func() {
ob_start();
global $post;
$terms = get_the_terms($post->ID,'program-episode');
if ( ! empty( $terms ) && is_array( $terms ) ) {
foreach ( $terms as $term ) {
$tid = $term->term_id;
}
?>
<span>
<?php echo get_term_meta($tid, 'program-intro-description', true); ?>
</span>
<?php
}
return ob_get_clean();
}
add_shortcode('custom_desc', 'custom_desc_func');