Wordpress自定义帖子类型帖子没有显示

时间:2014-05-09 14:35:37

标签: php wordpress custom-post-type

我很难搞清楚可能出现的问题。我有自定义帖子类型'预订'。即使有插入帖子,帖子也没有显示,只有'没有找到预订'可见。您会注意到标签'Mine'和'All',其中包含帖子的数量。请帮忙。我附上了截图。

Screenshot of the issue.

function aviators_booking_create_post_type() {
$labels = array(
    'name'               => __( 'Booking', 'aviators' ),
    'singular_name'      => __( 'Booking', 'aviators' ),
    'add_new'            => __( 'Add New', 'aviators' ),
    'add_new_item'       => __( 'Add New Booking', 'aviators' ),
    'edit_item'          => __( 'Edit Booking', 'aviators' ),
    'new_item'           => __( 'New Booking', 'aviators' ),
    'all_items'          => __( 'All Booking', 'aviators' ),
    'view_item'          => __( 'View Booking', 'aviators' ),
    'search_items'       => __( 'Search Booking', 'aviators' ),
    'not_found'          => __( 'No Bookings found', 'aviators' ),
    'not_found_in_trash' => __( 'No Bookings found in Trash', 'aviators' ),
    'parent_item_colon'  => '',
    'menu_name'          => __( 'Bookings', 'aviators' ),
);

$capabilities = array(
    'publish_posts' => 'publish_for_subscriber',
    'edit_posts' => 'edit_for_subscriber',
    'edit_published_posts' => 'edit_published_for_subscriber',
    'edit_others_posts' => 'edit_others_for_subscriber',
    'delete_posts' => 'delete_for_subscriber',
    'delete_others_posts' => 'delete_others_for_subscriber',
    'read_private_posts' => 'read_private_for_subscriber',
    'read_post' => 'read_for_subscriber'
);

register_post_type( 'booking',
        array(
            'labels'              => $labels,
            'supports'            => array( 'title', 'author' ),
            'public'              => true,
            'exclude_from_search' => true,
            'show_in_nav_menus'   => false,
            'capability_type' => 'for_subscriber',
            'capabilities' => $capabilities,
            'menu_position'       => 32,
            'menu_icon'           => get_template_directory_uri() . '/aviators/plugins/faq/assets/img/faq.png',
        )
    );
}

add_action( 'init', 'aviators_booking_create_post_type' );

1 个答案:

答案 0 :(得分:1)

刚才有类似的事发生在我身上,在我使用这个功能之后它很顺利。

flush_rewrite_rules();

在register_taxonomy

关闭后尝试

喜欢这个

register_post_type( 'booking',
    array(
        'labels'              => $labels,
        'supports'            => array( 'title', 'author' ),
        'public'              => true,
        'exclude_from_search' => true,
        'show_in_nav_menus'   => false,
        'capability_type' => 'for_subscriber',
        'capabilities' => $capabilities,
        'menu_position'       => 32,
        'menu_icon'           => get_template_directory_uri() . '/aviators/plugins/faq/assets/img/faq.png',
    )
);
flush_rewrite_rules();

有关详细信息,请查看Codex Function Reference/flush rewrite rules