Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?
// custom taxonomy == GENRE
// custom taxonomy meta name == GENRE_NAME
// ADD TAXONOMY META FEILD TO "NEW" SCREEN
// --------------------------------------------------------------------------------------
add_action( 'GENRE_add_form_fields', 'GENRE_add_form_fields', 10, 2 );
function GENRE_add_form_fields($taxonomy) {
?>
<div class="form-field term-group">
<label>Meta Feild A</label>
<input name="GENRE_META" />
</div>
<?
}
// ADD TAXONOMY META FEILD TO "EDIT" SCREEN
// --------------------------------------------------------------------------------------
add_action( 'GENRE_edit_form_fields', 'edit_GENRE_meta_field', 10, 2 );
function edit_GENRE_meta_field( $term, $taxonomy ){
$GENRE_META = get_term_meta( $term->term_id, 'GENRE_META', true );
?>
<tr>
<th>
<label>Meta Feild A</label>
</th>
<td>
<input name="GENRE_META" value='<?= $GENRE_META ?>' />
</td>
</tr>
<?
}
// SAVE TAXONOMY META
// --------------------------------------------------------------------------------------
add_action( 'created_GENRE', 'save_GENRE_meta', 10, 2 );
function save_GENRE_meta( $term_id, $tt_id ){
if ( isset( $_POST['GENRE_META'] ) && '' !== $_POST['GENRE_META'] )
add_term_meta( $term_id, 'GENRE_META', $_POST['GENRE_META'] , true );
}
// SAVE EDITED TAXONOMY META
// --------------------------------------------------------------------------------------
add_action( 'edited_GENRE', 'update_GENRE_meta', 10, 2 );
function update_GENRE_meta( $term_id, $tt_id ){
if( isset( $_POST['GENRE_META'] ) && '' !== $_POST['GENRE_META'] )
update_term_meta( $term_id, 'GENRE_META', $_POST['GENRE_META'] );
}
// ADD TO MANAGE SCREEN 1/2
// --------------------------------------------------------------------------------------
add_filter('manage_edit-GENRE_columns', 'add_GENRE_column' );
function add_GENRE_column( $columns ){
$columns['GENRE'] = 'GENRE';
return $columns;
}
// ADD TO MANAGE SCREEN 2/2
// --------------------------------------------------------------------------------------
add_filter('manage_GENRE_custom_column', 'add_GENRE_column_content', 10, 3 );
function add_GENRE_column_content( $content, $column_name, $term_id ){
if( $column_name !== 'GENRE') return $content;
return get_term_meta( $term_id, 'GENRE_META', true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment