Skip Navigation

[Resolved] How to filter taxonomy Archive to display specific post type post

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to filter taxonomy Archive to display specific post type post

Solution:
You can use WordPress standard function 'pre_get_posts' in order to filter the taxonomy archive to display the post from specific post type.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/archive-page-url/#post-903947

Relevant Documentation:

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by jenniferP 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#902617

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

Thanks!
Jen

#902740

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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

#903893

So by adding this code then this URL, hidden link will only show case-study post types with the adjacencies category?

or should I be using a different URL?

#903947

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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

#903959

You can close this. What I ended up doing is making a case-study taxonomy with the same categories and then using that for the menus.

Thanks!
Jen