Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 632 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unregister custom post type from Wordpress

#1
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')
)
);
Reply

#2
Try this code (with a large priority number)

function custom_unregister_theme_post_types() {
global $wp_post_types;

if ( isset( $wp_post_types["portfolio"] ) ) {
unset( $wp_post_types[ "portfolio" ] ); //UPDATED
}

}
add_action( 'init', 'custom_unregister_theme_post_types', 20 );

Note: make sure that the registered post type name is `portfolio` or `portfolios` (with s), register_post_type( ***$post_type***, $args )

**UPDATED:** `unset( $wp_post_types[ "portfolio" ] ); //UPDATED`
Reply

#3
Your code look good! But if you unregister the post_type... the posts in it go away... So don't unregister it too soon. Before you unregister the post type, migrate the posts from the post_type to normal posts. This plugin is handy for that:

[To see links please register here]


But if you don't want to migrate the video posts to the default posts... You'll have to modify your loop to include those portfolio-type posts:

function add_custom_post_type_to_query( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array('post', 'portfolio') );
}
}
add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

& don't forget to visit the permalinks page when working with custom post types to get WordPress to recognize the changes you've made.
Reply

#4
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);
Reply

#5
Here is the code for unregistering custom post types in wordpress. Just remember that you need to clear your functions.php from function that registered your post type in first place.

if( !function_exists( 'prefix_unregister_post_type' ) ) {
function prefix_unregister_post_type() {
unregister_post_type( 'portfolio' );
}
}
add_action('init','prefix_unregister_post_type');

Reply

#6
If the post type refuses to unregister, and if the "register_post_type" function isn't in functions.php, see if the registration is saved in a "must use plugin". As a reminder I place this comment at the top of my functions.php

/* if something is stuck, look in must use plugins!!! */
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through