发布后无法编辑或删除wordpress自定义帖子类型

时间:2018-02-16 05:55:05

标签: php wordpress

我的网站上运行了一些自定义帖子类型,一旦发布,似乎无法对其进行更改。我一直在这里挖掘,并认为它可能与capability_type和相关的权限有关,但我所看到的所有答案都有a)没有效果或b)删除了我的能力完全访问帖子。这是注册帖子类型的功能插件中的代码:

function event_post_type() {

$labels = array(
    'name'                  => _x( 'Events', 'Post Type General Name', 'text_domain' ),
    'singular_name'         => _x( 'Event', 'Post Type Singular Name', 'text_domain' ),
    'menu_name'             => __( 'Events', 'text_domain' ),
    'name_admin_bar'        => __( 'Event', 'text_domain' ),
    'archives'              => __( 'Event Archives', 'text_domain' ),
    'attributes'            => __( 'Event Attributes', 'text_domain' ),
    'parent_item_colon'     => __( 'Parent Event:', 'text_domain' ),
    'all_items'             => __( 'All Events', 'text_domain' ),
    'add_new_item'          => __( 'Add New Event', 'text_domain' ),
    'add_new'               => __( 'Add New', 'text_domain' ),
    'new_item'              => __( 'New Event', 'text_domain' ),
    'edit_item'             => __( 'Edit Event', 'text_domain' ),
    'update_item'           => __( 'Update Event', 'text_domain' ),
    'view_item'             => __( 'View Event', 'text_domain' ),
    'view_items'            => __( 'View Events', 'text_domain' ),
    'search_items'          => __( 'Search Event', 'text_domain' ),
    'not_found'             => __( 'Not found', 'text_domain' ),
    'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
    'featured_image'        => __( 'Featured Image', 'text_domain' ),
    'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
    'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
    'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
    'insert_into_item'      => __( 'Insert into event', 'text_domain' ),
    'uploaded_to_this_item' => __( 'Uploaded to this event', 'text_domain' ),
    'items_list'            => __( 'Events list', 'text_domain' ),
    'items_list_navigation' => __( 'Events list navigation', 'text_domain' ),
    'filter_items_list'     => __( 'Filter events list', 'text_domain' ),
);
$args = array(
    'label'                 => __( 'Event', 'text_domain' ),
    'description'           => __( 'Compositions, pieces, events!', 'text_domain' ),
    'labels'                => $labels,
    'supports'              => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', ),
    'taxonomies'            => array( 'event_category', ' tags' ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 20,
    'menu_icon'             => 'dashicons-calendar',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => true,
    'exclude_from_search'   => true,
    'publicly_queryable'    => false,
    'capability_type'       => 'post',

);
register_post_type( 'event', $args );

}
add_action( 'init', 'event_post_type', 0 );

非常感谢任何想法 - 仍然感觉很新!

2 个答案:

答案 0 :(得分:0)

您可以使用此代码

//---Events Custom post type--
function create_post_type_events() {

    register_post_type( 'events',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'Events' ),
                'singular_name' => __( 'Event' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'events'),
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields' ),
        )
    );
}
// Hooking up our function to theme setup
add_action( 'init', 'create_post_type_events' );
/*
* Creating a function to create our CPT
*/

function custom_post_type_events() {

// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Events', 'Post Type General Name', 'twentythirteen' ),
        'singular_name'       => _x( 'Event', 'Post Type Singular Name', 'twentythirteen' ),
        'menu_name'           => __( 'Events', 'twentythirteen' ),
        'parent_item_colon'   => __( 'Parent Event', 'twentythirteen' ),
        'all_items'           => __( 'All Events', 'twentythirteen' ),
        'view_item'           => __( 'View Event', 'twentythirteen' ),
        'add_new_item'        => __( 'Add New Event', 'twentythirteen' ),
        'add_new'             => __( 'Add New', 'twentythirteen' ),
        'edit_item'           => __( 'Edit Event', 'twentythirteen' ),
        'update_item'         => __( 'Update Event', 'twentythirteen' ),
        'search_items'        => __( 'Search Event', 'twentythirteen' ),
        'not_found'           => __( 'Not Found', 'twentythirteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );

// Set other options for Custom Post Type

    $args = array(
        'label'               => __( 'events', 'twentythirteen' ),
        'description'         => __( 'Event news and reviews', 'twentythirteen' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        // You can associate this CPT with a taxonomy or custom taxonomy. 
        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        */  
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
    );
    // Registering your Custom Post Type
    register_post_type( 'events', $args );
}

答案 1 :(得分:0)

检查您的functions.php中是否有其他可能正在注册自定义帖子类型的代码(例如,使用register_post_type)。

更新或删除顽固的自定义帖子类型时遇到类似的问题。忽略了一些代码,以注册要添加到搜索中的帖子类型。