I added a custom column to the manage categories admin page.
The code is generalized because is more specific in my case, but the meaning is the same
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 = mytheme_get_custom_field( $term_id );
if( empty( $content ) )
{
// If column is empty, put a minus
$content = '-';
}
}
return $content;
}
add_filter( 'manage_category_custom_column', 'mytheme_custom_column_fill', 10, 3 );
Then a I added a new custom field in the category creation form and saved it in this way.
/*
* Saves category custom field on category create
*
*/
function mytheme_save_custom_field( $term_id ){
if( isset( $_POST['my_custom_field'] ) ){
mytheme_save_custom_field( $_POST['my_custom_field'], $term_id );
}
}
add_action( 'created_category', 'mytheme_save_custom_field');
When I create the category, Wordpress sends the form with Ajax and adds automatically the new category row to the table.
The custom field should be showed in the table after creation, but always prints a '-', like "the custom field is empty", but when I reload the page, the field apperas correctly.
I think the problem is in this hook, that fires after the ajax response is sent, but not sure.
add_action( 'created_category', 'mytheme_save_custom_field');