I have a custom taxonomy hierarchical, that I want to limit the parent category to only top level. e.g:
<code>Subject A
- Child 1
- Child 2
Subject B
- Child 1
- Child 2
</code>
<code>Subject A
- Child 1
- Child 2
Subject B
- Child 1
- Child 2
</code>
Subject A
- Child 1
- Child 2
Subject B
- Child 1
- Child 2
So I’d like the option for parent category when creating a new item be limited to only Subject A or Subject B
the top level only.
I found someone doing it like the following Custom taxonomy – limit parent dropdown depth
<code>add_filter( 'taxonomy_parent_dropdown_args', 'limit_parents_wpse_106164', 10, 2 );
function limit_parents_wpse_106164( $args, $taxonomy ) {
if ( 'subjects' != $taxonomy ) return $args; // no change
$args['depth'] = '1';
return $args;
}
</code>
<code>add_filter( 'taxonomy_parent_dropdown_args', 'limit_parents_wpse_106164', 10, 2 );
function limit_parents_wpse_106164( $args, $taxonomy ) {
if ( 'subjects' != $taxonomy ) return $args; // no change
$args['depth'] = '1';
return $args;
}
</code>
add_filter( 'taxonomy_parent_dropdown_args', 'limit_parents_wpse_106164', 10, 2 );
function limit_parents_wpse_106164( $args, $taxonomy ) {
if ( 'subjects' != $taxonomy ) return $args; // no change
$args['depth'] = '1';
return $args;
}
Which seem to work fine IF we refresh the page after adding the new item, otherwise the child new item will still be shown in the dropdown after entering them.
Any way to fix this issue?