admin管理员组文章数量:1420181
I have a CPT called Clubs
. To 'categorise' posts depending on if clubs are in the same league or cup competition (or neither), I also have a custom taxonomy called Opposition
.
To show which clubs are in either the same competition, I am trying to create a page that functions like an Archive page where these specific Clubs
posts are displayed: /clubs/opposition/
To do this, I've created a taxonomy-opposition.php
template file and edited the functions.php
file with the following:
// Clubs Post Type
function clubs_init() {
$labels = array(
'name' => 'Clubs',
'singular_name' => 'Club',
'add_new' => 'Add New Club',
'add_new_item' => 'Add New Club',
'edit_item' => 'Edit Club',
'new_item' => 'New Club',
'all_items' => 'All Clubs',
'view_item' => 'View Club',
'search_items' => 'Search Clubs',
'not_found' => 'No Clubs Found',
'not_found_in_trash' => 'No Clubs found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Clubs',
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'taxonomies' => array( 'clubs', 'opposition' ),
'query_var' => true,
'rewrite' => array(
'slug' => 'clubs',
'with_front' => false
),
'menu_icon' => 'dashicons-shield',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'
)
);
register_post_type( 'clubs', $args );
}
add_action( 'init', 'clubs_init' );
// Opposition Taxonomy
function opposition_taxonomy() {
$labels = array(
'search_items' => 'Search Opposition',
'menu_name' => 'Opposition'
);
register_taxonomy( 'opposition', 'clubs',
array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_admin_column' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'clubs',
'with_front' => false
),
) );
}
add_action( 'init', 'opposition_taxonomy' );
The result when I try to access /clubs/opposition
, though, is an Error 404. The thing baffling me is that I've done something similar for my Players
CPT, creating a custom Squad
taxonomy page that does display. And I've followed exactly the same steps in trying to create an Opposition
page.
(I have flushed the permalinks)
I've referred to existing questions, but so far haven't found the solution:
- Custom taxonomy archive page not working
- Custom taxonomy template not working
- custom taxonomy - Template not working
- Taxonomy page returns 404 page not found
I have a CPT called Clubs
. To 'categorise' posts depending on if clubs are in the same league or cup competition (or neither), I also have a custom taxonomy called Opposition
.
To show which clubs are in either the same competition, I am trying to create a page that functions like an Archive page where these specific Clubs
posts are displayed: /clubs/opposition/
To do this, I've created a taxonomy-opposition.php
template file and edited the functions.php
file with the following:
// Clubs Post Type
function clubs_init() {
$labels = array(
'name' => 'Clubs',
'singular_name' => 'Club',
'add_new' => 'Add New Club',
'add_new_item' => 'Add New Club',
'edit_item' => 'Edit Club',
'new_item' => 'New Club',
'all_items' => 'All Clubs',
'view_item' => 'View Club',
'search_items' => 'Search Clubs',
'not_found' => 'No Clubs Found',
'not_found_in_trash' => 'No Clubs found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Clubs',
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'taxonomies' => array( 'clubs', 'opposition' ),
'query_var' => true,
'rewrite' => array(
'slug' => 'clubs',
'with_front' => false
),
'menu_icon' => 'dashicons-shield',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'
)
);
register_post_type( 'clubs', $args );
}
add_action( 'init', 'clubs_init' );
// Opposition Taxonomy
function opposition_taxonomy() {
$labels = array(
'search_items' => 'Search Opposition',
'menu_name' => 'Opposition'
);
register_taxonomy( 'opposition', 'clubs',
array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_admin_column' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'clubs',
'with_front' => false
),
) );
}
add_action( 'init', 'opposition_taxonomy' );
The result when I try to access /clubs/opposition
, though, is an Error 404. The thing baffling me is that I've done something similar for my Players
CPT, creating a custom Squad
taxonomy page that does display. And I've followed exactly the same steps in trying to create an Opposition
page.
(I have flushed the permalinks)
I've referred to existing questions, but so far haven't found the solution:
- Custom taxonomy archive page not working
- Custom taxonomy template not working
- custom taxonomy - Template not working
- Taxonomy page returns 404 page not found
1 Answer
Reset to default 1You use the same slug clubs
to register your custom post type and in rewrite
when you register opposition
taxonomy.
Change rewrite
parameter in register_taxonomy()
'rewrite' => array(
'slug' => 'clubs/opposition',
'with_front' => false
),
The recognizable address will be clubs/opposition/{some-term-name}
and will display posts from custom category.
However, the clubs/opposition
address will still not work without additional code.
本文标签: custom post typesCPT Taxonomy As Archive Page – Error 404
版权声明:本文标题:custom post types - CPT Taxonomy As Archive Page – Error 404 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745319205a2653297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/clubs/opposition
. WordPress only lists posts on archives, and/clubs/opposition
isn't specific enough to list any posts. You need to create Opposition terms, and then you can list posts with those terms at/clubs/opposition/term-name
. – Jacob Peattie Commented Jul 16, 2019 at 6:15