I have a custom post type called slide
. It has content and some custom fields. I want WP to show the single.php
theme or single-slide.php
theme when the user clicks the slide single page link. the problem I have is that WP throws 404 error, when I want to see the single slide page.
here is my code in functions.php
:
function create_slide_post_type() {
$labels = array(
'name' => _x( 'اسلایدها', 'i2sa' ),
'singular_name' => _x( 'اسلاید', 'i2sa' ),
'menu_name' => _x( 'اسلایدها', 'i2sa' ),
'name_admin_bar' => _x( 'اسلاید', 'i2sa' ),
'add_new' => _x( 'افزودن', 'i2sa' ),
'add_new_item' => __( 'افزودن اسلاید جدید', 'i2sa' ),
'new_item' => __( 'اسلاید جدید', 'i2sa' ),
'edit_item' => __( 'ویرایش اسلاید', 'i2sa' ),
'view_item' => __( 'نمایش اسلاید', 'i2sa' ),
'all_items' => __( 'همه اسلایدها', 'i2sa' ),
'search_items' => __( 'جستجوی اسلایدها', 'i2sa' ),
'parent_item_colon' => __( 'اسلایدهای مادر:', 'i2sa' ),
'not_found' => __( 'اسلایدی پیدا نشد.', 'i2sa' ),
'not_found_in_trash' => __( 'اسلایدی در زباله دان پیدا نشد.', 'i2sa' )
);
$args = array(
'labels' => $labels,
'description' => "اسلایدهای شرکت i2sa",
'public' => true,
'exclude_from_search'=> true,
'publicly_queryable' => false,
'show_in_nav_menus' => false,
'menu_icon' => 'dashicons-images-alt2',
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'slide' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
);
register_post_type( 'slide', $args );
flush_rewrite_rules();
}
add_action( 'init', 'create_slide_post_type' );