lagallega lagallega - 1 month ago 7
PHP Question

How to add custom metaboxes to taxonomies?

So I know how to save things when a taxonomy is edited like this:

if( !function_exists('mytaxonomysave') ):
function mytaxonomysave($term_id, $tt_id, $taxonomy) {
if($taxonomy == 'series'){
if(isset($_POST['type'])){
update_term_meta($term_id, 'type', $_POST['type']);
}
}
}
endif;
add_action( 'edit_term', 'mytaxonomysave', 10, 3 );


But I have no idea how to add a the metabox to the proper areas, what can I do? whats the correct hook¿

Answer

The hook you're looking for is: {taxonomy}_add_form_fields so in your case you use:

function series_types() {
    ?>
    <div class="form-field term-description-wrap">
        <label for="tag-type">Type</label>
        <input type='text' name='tag-type'></input>
    </div>
    <?php
}
endif;
add_action('series_add_form_fields', 'series_types');