【问题标题】:Wordpress, Custom post Type give 404 if more than 1 post type如果超过 1 个帖子类型,Wordpress,自定义帖子类型会给出 404
【发布时间】: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


    【解决方案1】:

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

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

    您不能有两个具有相同 slug 的帖子类型,因此请更改其中一个的名称,不要忘记更新您的永久链接:转到 设置-> 永久链接并点击 底部的保存更改按钮而不更改任何设置,这只会更新永久链接表。这样就可以了..

    【讨论】:

      【解决方案2】:

      使用不同的帖子名称。您创建的帖子类型不会从数据库中删除。因此,使用其他名称创建新的帖子类型。选择永久链接设置以发布名称

      【讨论】:

        猜你喜欢
        • 2013-05-10
        • 2012-01-01
        • 2016-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多