dongqing220586 2015-11-17 20:17
浏览 67

WordPress - 自定义帖子类型单页上的404错误

I use a custom post type, which also should have a custom taxonomy. When I visit the archive page /kollektion/ I can see all items of this CPT, when I visit /kollektion/mytaxonomy1/ I can see all items which are assigned to this taxonomy.

When I click on the single item of the custom post type, I get a 404 error. I also tried to go into my WP dashboard and change and resave the permalinks again - with no success.

Does anybody see an error in my declaration which causes the 404 error on single pages of my custom post type?

Thanks.

functions.php: Taxonomy

// register two taxonomies to go with the post type
function sm_register_taxonomy() {
    // set up labels
    $labels = array(
        'name'              => 'Kollektionen Categories',
        'singular_name'     => 'Kollektion Category',
        'search_items'      => 'Search Kollektion Categories',
        'all_items'         => 'All Kollektion Categories',
        'edit_item'         => 'Edit Kollektion Category',
        'update_item'       => 'Update Kollektion Category',
        'add_new_item'      => 'Add New Kollektion Category',
        'new_item_name'     => 'New Kollektion Category',
        'menu_name'         => 'Kollektion Categories'
    );
    // register taxonomy
    register_taxonomy( 'kollektionen', 'kollektion', array(
        'hierarchical' => true,
        'labels' => $labels,
        'query_var' => true,
        'show_admin_column' => true,
        'rewrite' => array(
            'slug' => 'kollektion', // This controls the base slug that will display before each term
            'with_front' => false // Don't display the category base before
        ),
    ) );
}
add_action( 'init', 'sm_register_taxonomy' );

functions.php: Custom post type

// Register Custom Post Type Kollektion
    function post_type_kollektion() {

        $labels = array(
            'name'                  => _x( 'Kollektionen', 'Post Type General Name', 'genesis' ),
            'singular_name'         => _x( 'Kollektion', 'Post Type Singular Name', 'genesis' ),
            'menu_name'             => __( 'Kollektion', 'genesis' ),
            'name_admin_bar'        => __( 'Kollektion', 'genesis' ),
            'parent_item_colon'     => __( 'Parent Item:', 'genesis' ),
            'all_items'             => __( 'All Items', 'genesis' ),
            'add_new_item'          => __( 'Add New Item', 'genesis' ),
            'add_new'               => __( 'Add New', 'genesis' ),
            'new_item'              => __( 'New Item', 'genesis' ),
            'edit_item'             => __( 'Edit Item', 'genesis' ),
            'update_item'           => __( 'Update Item', 'genesis' ),
            'view_item'             => __( 'View Item', 'genesis' ),
            'search_items'          => __( 'Search Item', 'genesis' ),
            'not_found'             => __( 'Not found', 'genesis' ),
            'not_found_in_trash'    => __( 'Not found in Trash', 'genesis' ),
            'items_list'            => __( 'Items list', 'genesis' ),
            'items_list_navigation' => __( 'Items list navigation', 'genesis' ),
            'filter_items_list'     => __( 'Filter items list', 'genesis' ),
        );
        $args = array(
            'label'                 => __( 'Kollektion', 'genesis' ),
            'description'           => __( 'Kollektionen', 'genesis' ),
            'labels'                => $labels,
            'supports'              => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', ),
            'taxonomies'            => array( 'post_tag', 'kollektionen' ),
            'hierarchical'          => false,
            'public'                => true,
            'show_ui'               => true,
            'show_in_menu'          => true,
            'menu_position'         => 5,
            'show_in_admin_bar'     => true,
            'show_in_nav_menus'     => true,
            'can_export'            => true,
            'has_archive'           => 'kollektion',
            'exclude_from_search'   => false,
            'publicly_queryable'    => true,
            'capability_type'       => 'page',
        );
        register_post_type( 'kollektion', $args );

    }
    add_action( 'init', 'post_type_kollektion');
}

function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'nav_menu_item', 'kollektion', 'kollektionen'
        ));
      return $query;
    }
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
  • 写回答

1条回答 默认 最新

  • doucheng9634 2015-11-17 21:02
    关注

    It looks like you have the same slug for taxonomy and custom post type. Try to change slug of taxonomy (or CPT) and resave the permalinks - this should help.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分