Remove taxonomies using register_post_type_args
-
21-04-2021 - |
Вопрос
The theme I'm using is adding taxonomies to CPT using register_post_type
and 'taxonomies' => array('portfolio-cat')
as one of the arguments.
I need to remove that particular taxonomy using register_post_type_args
.
I have tried with:
add_filter( 'register_post_type_args', 'change_portfolio_post_type_args', 10, 2 );
function change_portfolio_post_type_args( $args, $post_type ) {
if ( 'portfolio' === $post_type ) {
unset($args['taxonomies']); // Not working
unset($args['taxonomies'][0]); // Not working
$args['taxonomies'] = array(); // Not working
$args['taxonomies'] = array('category'); // It justs add another taxonomy
}
return $args;
}
How can I remove it, without touching theme core files?
Решение
Did you try this? Here: unregister_taxonomy_for_object_type()
Read more: https://developer.wordpress.org/reference/functions/unregister_taxonomy_for_object_type/
function unregister_portfolio_cat_for_portfolio() {
unregister_taxonomy_for_object_type( 'portfolio-cat', 'portfolio' );
}
add_action( 'init', 'unregister_portfolio_cat_for_portfolio' );
Не связан с wordpress.stackexchange