重定向到首页的自定义帖子类型存档

问题描述 投票:0回答:1

正如标题所示,我为“案例研究”创建了一个自定义帖子类型。我可以查看案例研究的帖子,但不能查看存档页面。当我查看存档页面时,它只是重定向到主页。我已经分析了大约3个小时的代码,似乎无法弄清楚。非常感谢您的帮助。

以下页面已创建:{archive-case-studies.php} {single-case-studies.php}

编辑:由于某种原因,当我打开隐身浏览器时,我可以查看/ case-studies /页面,但已清除了缓存,重新启动了浏览器等。我也无法查看对存档所做的更改-case-studies.php模板在隐身浏览器中。

CPT代码:

function case_studies_cpt() {

    $labels = array(
        'name'                  => __( 'Case Studies' ),
        'singular_name'         => __( 'Case Study' ),
        'menu_name'             => __( 'Case Studies' ),
        'name_admin_bar'        => __( 'Case Study' ),
        'all_items'             => __( 'All Case Studies' ),
        'add_new'               => __( 'Add New' ),
        'add_new_item'          => __( 'Add New Case Study' ),
        'edit_item'             => __( 'Edit Case Study' ),
        'new_item'              => __( 'New Case Study' ),
        'view_item'             => __( 'View Case Study' ),
        'search_items'          => __( 'Search Case Studies' ),
        'not_found'             => __( 'No Case Studies Found' ),
        'not_found_in_trash'    => __( 'No Case Study found in Trash' ),
        'parent_item_colon'     => __( 'Parent Case Study:' ),
        'update_item'           => __( 'Update Case Study' ),
        'items_list'            => __( 'Case Study list' ),
        'items_list_navigation' => __( 'Case Study list navigation' ),
        'filter_items_list'     => __( 'Filter Case Study list' ),
        'parent'                => __( 'Parent Case Study' )
    );
    $args = array(
        'label'                 => __( 'case-studies'),
        'description'           => __( ''),
        'labels'                => $labels,
        'supports'  => array(
            'title',
            'editor',
            'thumbnail',
            'revisions'
        ),
        'public'                => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'show_ui'               => true,
        'show_in_nav_menus'     => false,
        'show_in_menu'          => true,
        'show_in_admin_bar'     => false,
        'menu_position'         => 22,
        'menu_icon'             => 'dashicons-chart-area',
        'hierarchical'          => false,
        'taxonomies'            => array(),
        'has_archive'           => true,
        'query_var'             => true,
        'rewrite'   => array(
            'with_front'        => false,
            'slug'              => sanitize_title('Case Studies')
        ),
        'can_export'            => true,
        'capability_type'       => 'page'
);
    register_post_type( 'case-studies', $args );
}
add_action( 'init', 'case_studies_cpt', 0 );

分类代码:

add_action( 'init', 'case_studies_taxonomy', 0 );
function case_studies_taxonomy() {

  $labels = array(
    'name'                          => _x( 'Categories', 'taxonomy general name' ),
    'singular_name'                 => _x( 'Category', 'taxonomy singular name' ),
    'search_items'                  => __( 'Search Categories' ),
    'all_items'                     => __( 'All Categories' ),
    'parent_item'                   => __( 'Parent Category' ),
    'parent_item_colon'             => __( 'Parent Category:' ),
    'edit_item'                     => __( 'Edit Category' ),
    'update_item'                   => __( 'Update Category' ),
    'add_new_item'                  => __( 'Add New Category' ),
    'new_item_name'                 => __( 'New Category Name' ),
    'menu_name'                     => __( 'Case Study Categories' ),
  );

  register_taxonomy('categories',array('case-studies'), array(
    'hierarchical'                  => true,
    'labels'                        => $labels,
    'show_ui'                       => true,
    'show_admin_column'             => true,
    'query_var'                     => true,
    'rewrite' => array(
            'slug'                  => 'categories'
        )
  ));
}
php wordpress custom-post-type
1个回答
0
投票

进行更多的故障排除并找到了答案。必须从register_taxonomy中删除以下内容:

'rewrite' => array(
    'slug'                  => 'categories'
)
© www.soinside.com 2019 - 2024. All rights reserved.