You can’t set a level when you create the taxonomy.
The only way to enforce a level is by watching the term creation: Filter create_term
; that’s the earliest filter that allows us to change parent term ID. For no obvious reasons the filter pre_insert_term
is lacking that information … it would probably too easy.
Then change the parent term ID if the current on is already a second level ID.
Sample code, not tested:
add_action( 'create_term', function( $term_id, $tt_id, $taxonomy ) {
$term = get_term( $term_id );
// Nothing to do.
if ( empty( $term->parent ) )
return;
$parent = get_term( $term->parent, $taxonomy );
// This is a second level term, that's okay.
if ( empty( $parent->parent ) )
return;
wp_update_term( $term_id, $taxonomy, [ 'parent' => $parent->term_id ] );
}, 10, 3 );