admin管理员组文章数量:1410724
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' );
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' );
Share
Improve this question
asked Aug 6, 2014 at 12:02
Ramin OmraniRamin Omrani
3831 gold badge3 silver badges8 bronze badges
0
4 Answers
Reset to default 60You should set your publicly_queryable
argument to true
when registering your custom post type.
TAKE NOTE: Add flush_rewrite_rules()
, refresh the page once or twice and REMOVE IT IMMEDIATELY. You SHOULD NOT keep flush_rewrite_rules()
unless under the provisions as in the codex.
this is an expensive operation so it should only be used when absolutely necessary
Flush the rewrite rule from dashboard -> Settings->Permalink page. Click on save button and then check your slide details page. It will work now. Otherwise you can write this code flush_rewrite_rules()
in your create_slide_post_type()
function. See the Codex
Refresh your permalinks. Go to Admin->Settings->Permalinks and hit Save. It refreshes your permalinks and should help, especially if you are changing rewrite ( 'rewrite' => array( 'slug' => 'slide' ),)
You should set the following in your virtualhost apache:
<Directory /var/www/html/wordpress>
AllowOverride All
</Directory>
Then, refresh your permalinks: wp-admin->settings->permalinks. That's worked for me.
本文标签: Custom post type single page returns 404 error
版权声明:本文标题:Custom post type single page returns 404 error 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745006984a2637322.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论