我在产品分类法中添加了一些自定义元字段“艺术家”,它们工作得很好并保存到分类法中
/**
add meta data to artist taxonomy */
function artist_add_meta_fields( $taxonomy ) {
?>
<div class="form-field term-group">
<label for="artist_nickname"><?php _e( \'Nickname\', \'my-plugin\' ); ?></label>
<input type="text" id="artist_nickname" name="artist_nickname" />
</div>
<?php
}
add_action( \'artist_add_form_fields\', \'artist_add_meta_fields\', 10, 2 );
function artist_edit_meta_fields( $term, $taxonomy ) {
$artist_nickname = get_term_meta( $term->term_id, \'artist_nickname\', true );
?>
<tr class="form-field term-group-wrap">
<th scope="row">
<label for="artist_nickname"><?php _e( \'Nickname\', \'my-plugin\' ); ?></label>
</th>
<td>
<input type="text" id="artist_nickname" name="artist_nickname" value="<?php echo $artist_nickname; ?>" />
</td>
</tr>
<?php
}
add_action( \'artist_edit_form_fields\', \'artist_edit_meta_fields\', 10, 2 );
function artist_save_taxonomy_meta( $term_id, $tag_id ) {
if( isset( $_POST[\'artist_nickname\'] ) ) {
update_term_meta( $term_id, \'artist_nickname\', esc_attr( $_POST[\'artist_nickname\'] ) );
}
}
add_action( \'created_artist\', \'artist_save_taxonomy_meta\', 10, 2 );
add_action( \'edited_artist\', \'artist_save_taxonomy_meta\', 10, 2 );
但我在分类艺术家中找不到它们。前端php
//Get Taxonomy Meta
$artist_nickname = get_term_meta($term->term_id,\'artist_nickname\');
echo $artist_nickname;
但没有显示任何内容。我的问题在哪里?