Remove taxonomies using register_post_type_args

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x