I am trying to create an archive page using the custom post type and displaying one category within that custom post type.
i.e. I have a custom post type named case study and I want to create an archive of the case study entries that are tagged with the Adjacencies category.
I need to figure out what the URL would be so I can add it to my menu.
So I know the category URL would be hidden link
and that will show all the posts with the adjacencies category. so I am looking for how the URL would be if I wanted to just show the category adjacencies within the case study post type.
Currently, I am only using toolset types plugin.
This is for the site I am redoing with a new template here: hidden link
Hello. Thank you for contacting the Toolset support.
Well - you can use WordPress standard action pre_get_posts to filter your archive for specific post type.
Please add following code to your current theme's functions.php file:
Following code will be applied to only adjacencies term of category taxonomy,
add_action( 'pre_get_posts', 'func_tax_archive');
function func_tax_archive($query){
if (($query->is_main_query()) && is_tax('category','adjacencies')) {
/// Adjust the post type slug case-study if needed
$query->set( 'post_type','case-study');
}
Where:
- Adjust the post type slug case-study if needed with above code
hidden link will only show case-study post types with the adjacencies category?
==> Yes - it should.
Please add following code to your current theme's functions.php file.
add_action( 'pre_get_posts', 'func_tax_archive');
function func_tax_archive($query){
if (($query->is_main_query()) && is_tax('category','adjacencies')) {
/// Adjust the post type slug case-study if needed
$query->set( 'post_type','case-study');
}
Where:
- Adjust the post type slug case-study if needed with above code