WordPress功能“ register_post_type”未显示在管理员左侧边栏中

时间:2019-03-17 16:16:44

标签: php wordpress

我是PHP的新手。我正在学习在Wordpress中创建自定义帖子类型。但是,当我添加功能“ register_post_tyoe”时,新的自定义帖子类型不会显示在管理侧栏中。

这是我的代码:

function university_post_types() {
register_post_type('event', array(
    'public' => 'true',
    'label' => array(
    'name' => 'Events'

add_action('init', 'university_post_types');

谢谢!

2 个答案:

答案 0 :(得分:0)

这是我之前做过的事情:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'events',
        array(
            'labels' => array(  
                'name'               => _x( 'Events', 'post type general name' ),
                'singular_name'      => _x( 'Event', 'post type singular name' ),
                'add_new'            => _x( 'Add New', 'book' ),
                'add_new_item'       => __( 'Add New Event' ),
                'edit_item'          => __( 'Edit Event' ),
                'new_item'           => __( 'New Event' ),
                'all_items'          => __( 'All Events' ),
                'view_item'          => __( 'View Event' ),
                'search_items'       => __( 'Search Events' ),
                'not_found'          => __( 'No events found' ),
                'not_found_in_trash' => __( 'No events found in the Trash' ), 
                'parent_item_colon'  => '',
                'menu_name'          => 'Events'            ),
        'public' => true,
        'description'  => 'Add more events to the calendar',
        'has_archive' => true,
        'menu_position' => 5,
        'supports' => array( 'title', 'thumbnail', 'editor' ),
        )
    );
}

答案 1 :(得分:0)

我昨晚发现了。我用双引号(')设置为true是一个假的错误。我删除它后,它可以工作。谢谢大家的帮助!