The code is fully functional and tested. Add this in functions.php and check. I am giving you an example using the checkbox in the add and edit for the category.
function mytheme_custom_column( $columns )
{
$columns['my_column'] = 'My custom column';
return $columns;
}
add_filter( 'manage_edit-category_columns' , 'mytheme_custom_column' );
function mytheme_custom_column_fill( $content, $column_name, $term_id )
{
if ( 'my_column' == $column_name ) {
// Get content using $term_id
$content = get_term_meta( $term_id, 'show_category', true );
// be specific your content gets correct conent
if( !empty( $content ) )
{
//$content="your custom field content here";
return $content;
}else{
$content="-";
return $content;
}
}
}
add_filter( 'manage_category_custom_column', 'mytheme_custom_column_fill', 10, 3 );
// Add new term page
function mytheme_add_meta_fields( $taxonomy ) { ?>
<div class="form-field term-group">
<label for="show_category">
<?php _e( 'Show Category', 'codilight-lite' ); ?> <input type="checkbox" id="show_category" name="show_category" value="yes" />
</label>
</div><?php
}
add_action( 'category_add_form_fields', 'mytheme_add_meta_fields', 10, 2 );
// Edit term page
function mytheme_edit_meta_fields( $term, $taxonomy ) {
$show_category = get_term_meta( $term->term_id, 'show_category', true ); ?>
<tr class="form-field term-group-wrap">
<th scope="row">
<label for="show_category"><?php _e( 'Show Category', 'codilight-lite' ); ?></label>
</th>
<td>
<input type="checkbox" id="show_category" name="show_category" value="yes" <?php echo ( $show_category ) ? checked( $show_category, 'yes' ) : ''; ?>/>
</td>
</tr><?php
}
add_action( 'category_edit_form_fields', 'mytheme_edit_meta_fields', 10, 2 );
// Save custom meta
function mytheme_save_custom_field( $term_id, $tag_id ) {
if ( isset( $_POST[ 'show_category' ] ) ) {
update_term_meta( $term_id, 'show_category', 'yes' );
} else {
update_term_meta( $term_id, 'show_category', '' );
}
}
add_action( 'created_category', 'mytheme_save_custom_field', 10, 2 );
add_action( 'edited_category', 'mytheme_save_custom_field', 10, 2 );