我有一个自定义分类法,其中包含正在使用CMB2填充的自定义字段。我似乎不明白为什么我无法在前端填充此信息。
下面是在名为Placement的自定义分类法上生成自定义字段的代码。
add_action( \'cmb2_admin_init\', \'placement_register_taxonomy_metabox\' );
function placement_register_taxonomy_metabox() {
$prefix = \'placement_\';
$cmb_term = new_cmb2_box( array(
\'id\' => $prefix . \'placement\',
\'title\' => esc_html__( \'Title Handler\', \'veruscref-theme\' ), // Doesn\'t output for term boxes
\'object_types\' => array( \'term\' ), // Tells CMB2 to use term_meta vs post_meta
\'taxonomies\' => array( \'placement\' ), // Tells CMB2 which taxonomies should have these fields
// \'new_term_section\' => true, // Will display in the "Add New Category" section
) );
$cmb_term->add_field( array(
\'name\' => esc_html__( \'Loan Program Title\', \'veruscref-theme\' ),
\'desc\' => esc_html__( \'Will be displayed on transaction page\', \'veruscref-theme\' ),
\'id\' => $prefix . \'tax_header\',
\'type\' => \'title\',
\'on_front\' => false,
) );
$cmb_term->add_field( array(
\'name\' => esc_html__( \'Title\', \'veruscref-theme\' ),
\'id\' => $prefix . \'tax_title\',
\'type\' => \'text\',
) );
$cmb_term->add_field( array(
\'name\' => esc_html__( \'Small Title\', \'veruscref-theme\' ),
\'id\' => $prefix . \'tax_small_title\',
\'type\' => \'text\',
) );
下面是我的前端代码
<?php
$terms = get_terms(
array(
\'taxonomy\' => \'placement\',
\'hide_empty\' => 1,
\'exclude\' => array(4,23),
)
);
if ( ! empty( $terms ) && is_array( $terms ) ) { foreach ( $terms as $term ) { ?>
<?php
$title = get_term_meta( get_queried_object_id(), \'placement_tax_title\', true );
echo $title;
?>
<?php } } ?>
我的代码有什么问题?