You could use pre_get_posts to conditionally add the tax_query depending on post-type, here’s a simple example.
<?php
function wpse_377928( $the_query ){
$post_type = $the_query->get('post_type');
if ( 'type_a' === $post_type ) {
$tax_query = [
[
'taxonomy' => 'tax-1',
'field' => 'term_id',
'terms' => array(11, 12, 13),
]
];
}
elseif ( 'type_b' === $post_type ) {
$tax_query = [
[
'taxonomy' => 'tax-2',
'field' => 'term_id',
'terms' => array(21, 22, 23),
]
];
}
if ( !empty( $tax_query ) ) {
$the_query->set( 'tax_query', $tax_query );
}
}
add_action('pre_get_posts', 'wpse_377928');
Related Posts:
- WP_Query search posts by custom post type and custom taxonomy
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Custom post type and custom taxonomy 404 on page 2
- Foreach loop returning more than one item when querying taxonomy
- set object terms after some some time of published post – functions.php
- Custom Taxonomy – fields
- The most recent post of custom taxonomy
- Values inside a custom field to determine which category posts to display
- Display all posts in a custom post type, grouped by a custom taxonomy
- Custom Taxonomy with Custom Post Type Finds No Posts
- Custom query – alternate posts by category
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- how to group custom post type posts by custom taxonomy terms
- Custom Taxonomy List links being re-written
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Exclude current post when getting related post on custom post type and taxonomy
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Ordering Custom Post Types with WP_Query
- Show ACF field from custom taxonomy and display on the single template
- Display children and grandchildren of a custom post type
- Querying CPT with Two Taxonomies
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Conditional to modify query results
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- Querying Term Posts in Loop
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Can’t get order_by meta_value_num to work properly
- Filter by custom taxonomy slug on a custom post type
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- How to make sure content doesn’t display if selection is empty
- Archive for custom taxonomy lists all posts instead of current taxonomy
- wp_query check if integer exists in custom field’s array
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Custom-Posttype & Custom Taxonomy WP_Query
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Query Custom Post Type Taxonomy term with multiple parameters
- Retrieve custom post types by custom taxonomies with WP_Query
- WP_Query Custom Post Type if Category ID Equals
- Using page slug in wp_query
- Custom taxonomy wp_query woes.
- Creating two loops based on different logic
- Control content before and after custom post type loop
- Show message when query has no posts
- How to show all taxonomies within custom post type loop
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- Creating a non-hierarchical Taxonomy that behaves like categories
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- Using Wp_Query, Json to add Highcharts series data
- How to query Posts from a custom post type which contains a custom taxonomy?
- Query Posts that have Custom Taxonomy
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Using page title as a link to term archive
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Setup page template array in a custom post type
- Sorting the Loop by Taxonomy Value
- How do I ensure that post_type and Taxonomy use the same slug?
- Custom post type page with parameter
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- custom taxonomy pagination 404 error
- Ordering by meta value not working
- Get all post under custom post type grouped by custom filed value in custom taxonomy
- Check that a slug is present in the get_terms request
- pagination problem listing custom post types of taxonomy in wordpress
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Live search by custom tag
- Search result based on URL
- Query a custom taxonomy in a function to create an csv file
- Custom search for a custom post type in WordPress
- Custom Post By Category
- How to get the posts that my following users are liked?
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Display all Custom taxonomy terms and their relevant custom posts
- Strange behavior on WP_query
- Show custom taxonomy not in submenu
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- Loop carousel slider in wordpress
- How to Fix WordPress 500 Internal server error due to custom post type
- Get posts associated with custom taxonomy alternate way
- Loop with Custom Post Type and Taxonomies
- tax_query showing no results
- Exclude Custom Post Type from shared Custom Taxonomy
- WordPress Custom Post Type and sort by Tags
- How to display elements of different post types?
- Trying to combine multiple WordPress queries
- Looping taxonomy in taxonomy?
- Building a List of Posts grouped by custom taxonomy as the section header only to be displayed if at least one post is in that tax
- posting twice from an array?
- Pagination not working on homepage
- Custom Loop for custom post type. Compare by meta_value?
- Query Custom Post Type by Tag
- Attaching multiple custom taxonomies to one CPT?
- How to manage wordpress knowledge base/wiki/posts collections
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- Sort ACF by custom taxonomy
- Complex Custom Loop with Includes
- Dynamically count the number of custom post types associated to a custom taxonomy