繁体   English   中英

WordPress,自定义帖子类型如果超过1个帖子类型,则给出404

[英]Wordpress, Custom post Type give 404 if more than 1 post type

我知道这是普遍的问题。

首先,我想说-我尝试:刷新重写,重置永久链接设置,删除.htacces并再次使用永久链接设置创建,尝试: flush_rewrite_rules()

问题:使用“永久链接设置”时自定义post_type显示404-/%postname%/,但无法正常工作,内置帖子也存在同样的问题! 当我创建一个post_type时-它起作用,但是当创建下一个post_type时-仅工作添加最后一个帖子类型,第一个post_type给出404。这是我的Create post函数:

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 */
    }

这些Post类型必须是分层的 ,并且slug =>'/'我完全不知道为什么会有这个问题:(

最奇怪的部分是-为什么只能使用最后注册的帖子类型,为什么构建“帖子”不起作用

问题是您要创建两个具有相同子段的帖子类型。 您应该在其中之一更改。

'rewrite' => array( 'slug' => '/' ),

您不能同时拥有两种类型的帖子,因此请更改其中一种的名称,不要忘记更新您的永久链接:转到“设置”->“永久链接” ,然后单击底部的“ 保存更改”按钮,而不更改任何设置,这将只更新永久链接表。 这会做到的..

使用不同的帖子名称。 您创建的帖子类型不会从数据库中删除。 因此,请使用其他名称创建新的帖子类型。 选择“固定链接设置为帖子名称”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM