【发布时间】:2016-01-22 17:42:50
【问题描述】:
我知道这是常见问题。
首先我想说 - 我尝试:刷新重写,重置永久链接设置,删除 .htacces 并使用永久链接设置再次创建,尝试:flush_rewrite_rules()。
问题:使用永久链接设置 - /%postname%/ 时自定义 post_type 显示 404,无法正常工作,同样的问题是内置帖子!。 当我创建一个 post_type 时 - 它可以工作,但是当创建下一个时 - 只工作添加的最后一个帖子类型,第一个 post_type 给出 404。 这是我的创建帖子功能:
add_action( 'init', 'create_post_types', 0 );
function create_post_types() {
/***********************************
*
* Register post type - Svømming
*
***********************************/
$labels = array(
'name' => _x( 'Svømming', 'Post Type General Name', TD),
'singular_name' => _x( 'Svømming', 'Post Type Singular Name', TD ),
'menu_name' => __( 'Svømming', TD ),
'name_admin_bar' => __( 'Svømming', TD ),
);
$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes');
$args = array(
'label' => __( 'Svømming', TD ),
'description' => __( 'Svømming', TD ),
'labels' => $labels,
'supports' => $supports,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => THEMEURL.'/img/swimming2x2.svg',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => '/' ),
'capability_type' => 'page',
);
register_post_type( 'svomming', $args );
/***********************************
*
* Register post type - Stup
*
***********************************/
$labels = array(
'name' => _x( 'Stup', 'Post Type General Name', TD),
'singular_name' => _x( 'Stup', 'Post Type Singular Name', TD ),
'menu_name' => __( 'Stup', TD ),
'name_admin_bar' => __( 'Stup', TD ),
);
$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes');
$args = array(
'label' => __( 'Stup', TD ),
'description' => __( 'Stup', TD ),
'labels' => $labels,
'supports' => $supports,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => THEMEURL.'/img/stup.svg',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => '/' ),
'capability_type' => 'page',
);
register_post_type( 'stup', $args );
/* There will be 4 more post types */
}
这些帖子类型必须是分层,并且slug => '/' 我完全不知道为什么会出现这个问题:(
最奇怪的部分是 - 为什么只使用最后注册的帖子类型以及为什么构建“帖子”不起作用
【问题讨论】:
标签: php wordpress custom-post-type