使用REGISTER_POST_TYPE_ARGS删除分类

时间:2020-11-13 作者:RhymeGuy

我使用的主题是使用register_post_type\'taxonomies\' => array(\'portfolio-cat\') 作为论点之一。

我需要使用register_post_type_args.

我尝试过:

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;
}
如何在不接触主题核心文件的情况下删除它?

1 个回复
最合适的回答,由SO网友:Quang Hoang 整理而成

你试过这个吗?此处:unregister_taxonomy_for_object_type()

阅读更多: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\' );