I have a custom post type
// Set other options for Custom Post Type
$args = array(
'label' => __( 'document', 'ecse' ),
'description' => __( 'Upload Documents', 'ecse' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'custom-fields', 'excerpt' ,'thumbnail','page-attributes','tags'),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'sources' ),
'capability_type' => 'page',
And I have custom taxonomies for it
register_taxonomy( 'sources',...[ ... 'has_archive' => true,
'rewrite' => [
'hierarchical' => true,
"with_front" => false,
'ep_mask' => EP_PERMALINK | EP_PAGES,
'slug' => '/%sources%/'
register_taxonomy( 'forms', 'documents',[
'has_archive' => true,
'hierarchical' => true,
'rewrite' => [
'hierarchical' => true,
"with_front" => false,
'ep_mask' => EP_PERMALINK | EP_PAGES,
'slug' => '/documents/%postname%/'
],
'show_in_menu' => false,
'query_var' => true,
]);
I'm able to get the archive page to display a paginated list of the post type.... But the permalink for the single post type is being malformed
The base for my taxonomy permalink is http://xxxx/documents/%sources%/
where sources is the taxonomy if I use http://xxxx/documents/%sources%/%postname%/
Then the single page works....but I lose the "archive pagination" thus http://xxxx/documents/%sources%/page/2/
doesn't work.
How do I get both sinlge and archive pages to work for custom post types?
I have a custom post type
// Set other options for Custom Post Type
$args = array(
'label' => __( 'document', 'ecse' ),
'description' => __( 'Upload Documents', 'ecse' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'custom-fields', 'excerpt' ,'thumbnail','page-attributes','tags'),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'sources' ),
'capability_type' => 'page',
And I have custom taxonomies for it
register_taxonomy( 'sources',...[ ... 'has_archive' => true,
'rewrite' => [
'hierarchical' => true,
"with_front" => false,
'ep_mask' => EP_PERMALINK | EP_PAGES,
'slug' => '/%sources%/'
register_taxonomy( 'forms', 'documents',[
'has_archive' => true,
'hierarchical' => true,
'rewrite' => [
'hierarchical' => true,
"with_front" => false,
'ep_mask' => EP_PERMALINK | EP_PAGES,
'slug' => '/documents/%postname%/'
],
'show_in_menu' => false,
'query_var' => true,
]);
I'm able to get the archive page to display a paginated list of the post type.... But the permalink for the single post type is being malformed
The base for my taxonomy permalink is http://xxxx/documents/%sources%/
where sources is the taxonomy if I use http://xxxx/documents/%sources%/%postname%/
Then the single page works....but I lose the "archive pagination" thus http://xxxx/documents/%sources%/page/2/
doesn't work.
How do I get both sinlge and archive pages to work for custom post types?
Share Improve this question edited Dec 17, 2019 at 14:18 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Dec 17, 2019 at 14:04 KendallKendall 1891 gold badge1 silver badge10 bronze badges 1 |1 Answer
Reset to default -1WordPress can handle this automatically by creating a page called archive-CustomPostTypePage.php through register_post_type() function.
eg. archive-documents.php
You need to register your post type in the functions and the name has to be the same as the php file name above eg:
register_post_type('documents', array(
// YOUR ARRAY HERE
));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744896382a4599721.html
documents
?) and rewrite parameters are used inregister_post_type()
? – nmr Commented Dec 17, 2019 at 17:13