php – 从WordPress取消注册自定义帖子类型

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 从WordPress取消注册自定义帖子类型脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试删除通过wordpress中的其他主题设置的自定义帖子类型,现在所有这些帖子都分配给了post_tyPE投资组合.经过大量的搜索,我找到了下面的代码,但它似乎没有用.我尝试将它添加到新主题和旧主题functions.PHP.

我想删除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');

注册帖子类型的代码

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

解决方法

我能够使用以下代码wordpress 4.6.1中删除它:

function delete_post_type(){
  unregister_post_type( 'portfolio' );
}
add_action('init','delete_post_type',100);

脚本宝典总结

以上是脚本宝典为你收集整理的php – 从WordPress取消注册自定义帖子类型全部内容,希望文章能够帮你解决php – 从WordPress取消注册自定义帖子类型所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。