I'm trying to remove a custom post type that was set via a different theme in Wordpress, now all of those posts are assigned to a post_type
of portfolio
. After a lot of searching, I found the code below, however it doesn't seem to work. I tried adding it both to the new theme and the old themes functions.php
.
I want to remove the post_type and have the posts categorized and displayed as a normal post. I think what I'm doing is correct, but can't seem to get it to work - I've posted both the code for the custom post type and the code to unregister the posts assigned to it.
Code to uregister post type
if ( ! function_exists( 'unregister_post_type' ) ) :
function unregister_post_type() {
global $wp_post_types;
if ( isset( $wp_post_types[ 'portfolio' ] ) ) {
unset( $wp_post_types[ 'portfolio' ] );
return true;
}
return false;
}
endif;
add_action('init', 'unregister_post_type');
Code that registered the post type
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __('Portfolio Items'),
'singular_name' => __('Portfolio Item'),
'add_new_item' => __('Add New Portfolio Item'),
'edit_item' => __('Edit Portfolio Item'),
'new_item' => __('New Portfolio Item'),
'view_item' => __('View Portfolio Item'),
'search_items' => __('Search Portfolio Items'),
'not_found' => __('No portfolio items found'),
'not_found_in_trash' => __('No portfolio items found in Trash')
),
'public' => true,
'show_ui' => true,
'hierarchical' => false,
'menu_position' => 7,
//'rewrite' => array('slug' => 'portfolio'),
'rewrite' => true,
'_built_in' => false,
'taxonomies' => array( 'post_tag','category','portfolio_tag', 'portfolio_category', 'client'),
'supports' => array( 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions')
)
);
I was able to remove it in WordPress 4.6.1 using this code:
function delete_post_type(){
unregister_post_type( 'portfolio' );
}
add_action('init','delete_post_type', 100);