Question

I'm having a hard time figuring out what could be the issue. I have a Custom Post Type 'Booking'. Even there are post inserted to it, posts are not showing and only 'No Bookings found' is visible. You will notice the labels 'Mine' and 'All' which contains the number of post has value on it. Please help. I attached the screenshot.

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' );
Was it helpful?

Solution

Something similar happened to me a while ago, it gone well after I used this functon.

flush_rewrite_rules();

Try after the closure of the register_taxonomy

Like this

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

For further details check on Codex Function Reference/flush rewrite rules

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top