Archived topic
How to make archive page for custom post type/tax
8 replies · Started by Eaydman on September 25, 2020
I have a custompost type called Video, and added a custom tax called video-category.
How do I make a archive page that works with my post type ?
Im running All the newest beta of GeneratePress theme and Pro version.
Hi there,
does your CPT include the 'has_archive' => true, argument ?
Ah no - It was false, but have change it to true now.
On my page domain.com/video-category/tax-slug/ I still get "Nothing Found"
This is how my settings looks link in the CPT.
$args = array(
'label' => __( 'video', 'xxxxx' ),
'description' => __( '', 'xxxxx' ),
'labels' => $labels,
'menu_icon' => 'dashicons-screenoptions',
'supports' => array('title', 'editor', 'revisions', 'thumbnail', 'author', 'custom-fields', ),
'taxonomies' => array(),
'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' => true,
'hierarchical' => false,
'exclude_from_search' => true,
'show_in_rest' => true,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'video'),
);
What do I then do ?
You will need to create a copy of the themes archive.php template and place that in your child theme folder.
The new archive will need to match the rewrite slug you have added to your template.
eg.
archive-video.php
I have copyed the "archive.php" and renamed it to "archive-video.php" in the child theme.
But i still get the "Nothing Found".
Do i have to make some changes to the "archive-video.php" file ?
Or http://www.domain.com/video/ works fine, that show an archive page for all the post in that post-type.
But I have a Custom-Post-Type (Video), where I have added a custom Tax named (video-category).
So when I make a link to a Custom Tax. http://www.domain.com/video-category/cat-name that page says: "Nothing Found"
This article explains:
https://premium.wpmudev.org/blog/add-custom-post-types-to-tags-and-categories-in-wordpress/
I added the code:
function add_custom_types_to_tax( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// Get all your post types
$post_types = get_post_types();
$query->set( 'post_type', $post_types );
return $query;
}
}
add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
But my CPT Custom Tax is still showing "Nothing Found" on http://www.domain.com/custom-tax/tax-name
This should all happen automatically without the need for functions or custom templates.
Have you try re-saving your permalinks in "Settings > Permalinks"?