admin管理员组文章数量:1315955
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?
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?
Share Improve this question asked Nov 13, 2020 at 22:21 RhymeGuyRhymeGuy 1471 silver badge6 bronze badges1 Answer
Reset to default 1Did you try this? Here: unregister_taxonomy_for_object_type()
Read more: https://developer.wordpress/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' );
本文标签: custom post typesRemove taxonomies using registerposttypeargs
版权声明:本文标题:custom post types - Remove taxonomies using register_post_type_args 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741995956a2410048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论