Not Able to Add Custom Field to Custom Taxonomy

I have CPT called Movie and it has a Custom Taxonomy called genres. I am bale to see and create Custom Post Types post from this CPT but I am not able to add a Custom Field to the Taxonomy (genres)

I used both od these methods

A:

function genres_taxonomy_custom_fields($tag) {
$t_id = $tag->term_id;
$term_meta = get_option( “taxonomy_term_$t_id” );
?>

<tr class=”form-field”>
<th scope=”row” valign=”top”>
<label for=”presenter_id”><?php _e(‘WordPress User ID’); ?></label>
</th>
<td>
<input type=”text” name=”term_meta[presenter_id]” id=”term_meta[presenter_id]” size=”25″ style=”width:60%;” value=”<?php echo $term_meta[‘presenter_id’] ? $term_meta[‘presenter_id’] : ”; ?>”><br />
<span class=”description”><?php _e(‘The Presenter’s WordPress User ID’); ?></span>
</td>
</tr>

<?php
}

function save_taxonomy_custom_fields( $term_id ) {
if ( isset( $_POST[‘term_meta’] ) ) {
$t_id = $term_id;
$term_meta = get_option( “taxonomy_term_$t_id” );
$cat_keys = array_keys( $_POST[‘term_meta’] );
foreach ( $cat_keys as $key ){
if ( isset( $_POST[‘term_meta’][$key] ) ){
$term_meta[$key] = $_POST[‘term_meta’][$key];
}
}
update_option( “taxonomy_term_$t_id”, $term_meta );
}
}

add_action( ‘genres_edit_form_fields’, ‘genres_taxonomy_custom_fields’, 10, 2 );
add_action( ‘edited_genres’, ‘save_taxonomy_custom_fields’, 10, 2 );

and B

function add_taxonomy_meta_field($term) {
$t_id = $term->term_id;
$term_meta = get_option( “taxonomy_$t_id” ); ?>
<tr class=”form-field”>
<th scope=”row” valign=”top”><label for=”term_meta[custom_term_meta]”><?php _e( ‘Example meta field’, ‘pippin’ ); ?></label></th>
<td>
<input type=”text” name=”term_meta[custom_term_meta]” id=”term_meta[custom_term_meta]” value=”<?php echo esc_attr( $term_meta[‘custom_term_meta’] ) ? esc_attr( $term_meta[‘custom_term_meta’] ) : ”; ?>”>
<p class=”description”><?php _e( ‘Enter a value for this field’,’pippin’ ); ?></p>
</td>
</tr>
<?php
}
add_action( ‘genres_edit_form_fields’, ‘add_taxonomy_meta_field’, 10, 2 );

function save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST[‘term_meta’] ) ) {
$t_id = $term_id;
$term_meta = get_option( “taxonomy_$t_id” );
$cat_keys = array_keys( $_POST[‘term_meta’] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST[‘term_meta’][$key] ) ) {
$term_meta[$key] = $_POST[‘term_meta’][$key];
}
}
update_option( “taxonomy_$t_id”, $term_meta );
}
}
add_action( ‘edited_genres’, ‘save_taxonomy_custom_meta’, 10, 2 );
add_action( ‘create_genres’, ‘save_taxonomy_custom_meta’, 10, 2 );

No error but they are not adding any custom field to the Taxonomy.

Read more here:: Not Able to Add Custom Field to Custom Taxonomy

Leave a Reply

Your email address will not be published. Required fields are marked *