【问题标题】:JointsWP Custom Post Type Wordpress MenuJointsWP 自定义帖子类型 Wordpress 菜单
【发布时间】:2018-04-30 16:07:11
【问题描述】:

所以我完全遵循了 JointsWP 自定义帖子类型模板。但是在 wordpress 管理员中,在菜单中我的类别和标签不太正确。我需要删除属于帖子的类别和标签菜单项。

这是我的 CPT 的 wordpress 管理菜单的当前状态....

列表(我的 CPT,完全符合我的要求)
- 所有列表(工作)
- 添加新的(工作)
- 类别(我需要这个!这实际上与常规博客帖子的“帖子”类别相关联)
- 标签(我需要这个!这实际上连接到常规博客帖子的“帖子”标签)
- 列表类别(工作)
- 列表标签(工作)

我已经在我的 functions.php 中尝试了 hack 修复:

// Removing some menu items
function remove_menus() {
remove_menu_page( 'edit-tags.php?taxonomy=category&post_type=listings' );
remove_menu_page( 'edit-tags.php?taxonomy=post_tag&post_type=listings' );
}
add_action( 'admin_menu', 'remove_menus' );

这是我的 CPT 函数的副本,它基本上只是 JointsWP 附带的副本,我出于自己的目的编辑了它

function custom_post_example() { 
register_post_type( 'listings', 
    array('labels' => array(
        'name' => __('Listings', 'jointswp'), 
        'singular_name' => __('Listing', 'jointswp'), 
        'all_items' => __('All Listings', 'jointswp'), 
        'add_new' => __('Add New', 'jointswp'), 
        'add_new_item' => __('Add New Listing', 'jointswp'),
        'edit' => __( 'Edit', 'jointswp' ), 
        'edit_item' => __('Edit Listing', 'jointswp'), 
        'new_item' => __('New Listing', 'jointswp'),
        'view_item' => __('View Listing', 'jointswp'), 
        'search_items' => __('Search Listings', 'jointswp'), 
        'not_found' =>  __('Nothing found in the Database.', 'jointswp'),
        'not_found_in_trash' => __('Nothing found in Trash', 'jointswp'), 
        'parent_item_colon' => ''
        ), 

        'description' => __( 'This is the Listing custom post type', 'jointswp' ), 
        'public' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'show_ui' => true,
        'query_var' => true,
        'menu_position' => 8, 
        'menu_icon' => 'dashicons-building', 
        'rewrite'   => array( 'slug' => 'listings', 'with_front' => false ), 
        'has_archive' => 'listings', 
        'capability_type' => 'post',
        'hierarchical' => false,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'revisions', 'sticky')

    )
); 

register_taxonomy_for_object_type('category', 'listings');
register_taxonomy_for_object_type('post_tag', 'listings');
} 
add_action( 'init', 'custom_post_example');

register_taxonomy( 'listing_cat', 
    array('listings'), 
    array('hierarchical' => true,         
        'labels' => array(
            'name' => __( 'Listing Categories', 'jointswp' ),
            'singular_name' => __( 'Listing Category', 'jointswp' ),
            'search_items' =>  __( 'Search Listing Categories', 'jointswp' ),
            'all_items' => __( 'All Listing Categories', 'jointswp' ),
            'parent_item' => __( 'Parent Listing Category', 'jointswp' ),
            'parent_item_colon' => __( 'Parent Listing Category:', 'jointswp' ),
            'edit_item' => __( 'Edit Listing Category', 'jointswp' ),
            'update_item' => __( 'Update Listing Category', 'jointswp' ), 
            'add_new_item' => __( 'Add New Listing Category', 'jointswp' ),
            'new_item_name' => __( 'New Listing Category Name', 'jointswp' ) 
        ),
        'show_admin_column' => true, 
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'listing' ),
    )
);   

register_taxonomy( 'listing_tag', 
    array('listings'), 
    array('hierarchical' => false,            
        'labels' => array(
            'name' => __( 'Listing Tags', 'jointswp' ), 
            'singular_name' => __( 'Listing Tag', 'jointswp' ),
            'search_items' =>  __( 'Search Listing Tags', 'jointswp' ),
            'all_items' => __( 'All Listing Tags', 'jointswp' ), 
            'parent_item' => __( 'Parent Listing Tag', 'jointswp' ),
            'parent_item_colon' => __( 'Parent Listing Tag:', 'jointswp' ),
            'edit_item' => __( 'Edit Listing Tag', 'jointswp' ), 
            'update_item' => __( 'Update Listing Tag', 'jointswp' ), 
            'add_new_item' => __( 'Add New Listing Tag', 'jointswp' ),
            'new_item_name' => __( 'New Listing Tag Name', 'jointswp' )
        ),
        'show_admin_column' => true,
        'show_ui' => true,
        'query_var' => true,
    )
); 

【问题讨论】:

    标签: wordpress custom-post-type custom-taxonomy


    【解决方案1】:

    您可能在注册自定义帖子类型时传递了以下参数:

    'taxonomies'            => array( 'category', 'post_tag' ),
    

    此行会将默认类别和标签分类与您的自定义帖子类型相关联。如果您不想使用自定义帖子类型,则需要在该参数中传递空数组,如下所示:

    'taxonomies'            => array( ),
    

    所以这里是注册自定义帖子类型时要传递的参数数组:

    $args = array(
            'label'                 => __( '[name of CPT]', 'text_domain' ),
            'description'           => __( 'Post Type Description', 'text_domain' ),
            'labels'                => $labels, // array of labels
            'supports'              => array( ),
            'taxonomies'            => array( ),
            'hierarchical'          => false,
            'public'                => true,
            'show_ui'               => true,
            'show_in_menu'          => true,
            'menu_position'         => 5,
            'show_in_admin_bar'     => true,
            'show_in_nav_menus'     => true,
            'can_export'            => true,
            'has_archive'           => true,        
            'exclude_from_search'   => false,
            'publicly_queryable'    => true,
            'capability_type'       => 'page',
        );
        register_post_type( [custom post type name], $args );
    

    【讨论】:

    • 谢谢。它不见了。我尝试添加它,但没有任何改变。我在下面粘贴我的帖子类型函数的内容......它基本上只是 JointsWP 附带的,我为自己使用而编辑的(因为我对 CPT 还有些陌生)
    • 对不起。澄清。我已经用我的函数的粘贴内容更新了我的原始帖子(在你的分类修复之前)。谢谢!
    【解决方案2】:

    删除这些,解决了问题。

    register_taxonomy_for_object_type('category', 'listings');
    register_taxonomy_for_object_type('post_tag', 'listings');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多