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

时间:2015-11-17 20:17:56

标签: php wordpress

我使用自定义帖子类型,它也应该有自定义分类。当我访问存档页面/ kollektion /我可以看到此CPT的所有项目,当我访问/ kollektion / mytaxonomy1 /我可以看到分配给该分类的所有项目。

当我点击自定义帖子类型的单个项目时,我收到404错误。我还尝试进入我的WP仪表板并再次更改并重新保存永久链接 - 但没有成功。

是否有人在我的声明中看到错误导致我的自定义帖子类型的单个页面出现404错误?

感谢。

functions.php:分类

// 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:自定义帖子类型

// 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 个答案:

答案 0 :(得分:4)

看起来你对分类和自定义帖子类型有相同的slug。尝试改变分类法(或CPT)并重新获得永久链接 - 这应该有所帮助。