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
- Querying CPT with Two Taxonomies
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- List terms from Custom Taxonomy
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Optimised Code for Pulling Taxonomy Posts
- Show Post Count of a Category
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- Conditional to modify query results
- Is it possible to create a shortcode that will query a post based on taxonomies?
- wp_query to find posts by year and month
- 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?
- How to output wordpress custom tags separated by comma?
- Querying Term Posts in Loop
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Custom Post Type Loop within Shortcode
- Fetch taxonomies by custom post type id array
- Weird problem happening with custom taxonmy when creating/updating posts
- Group custom posts by custom taxonomy names
- Can’t get order_by meta_value_num to work properly
- How can i skip same post from taxonomy term?
- Filter by custom taxonomy slug on a custom post type
- Very Slow Page – How to Optimize # of Queries?
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Display CPT posts based on specific taxonomy
- How to display selected taxonomies by their parent
- Custom Field Order by Last Name and First Name
- shortcode to show custom post types by category
- get_posts of Custom Post Type AND Custom Taxonomy
- Query/list all terms and their custom post count
- Received nothing after executing AJAX post function
- How to make sure content doesn’t display if selection is empty
- Filtering WP_Query Dynamically on the Front-End
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Genesis filterable portfolio isotope [closed]
- wp_query check if integer exists in custom field’s array
- Wrong request query on cpt and tax
- Get custom post type list for every category shortcode
- Get custom taxonomies from multiple posts
- Pagination for Custom Taxonomy Page [duplicate]
- Search / Filter posts on Title/Content OR Tags
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Custom-Posttype & Custom Taxonomy WP_Query
- Custom loop with multiple taxonomy queries
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Custom taxonomy rewrite give pagination 404
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- creat filter with wp_query
- Custom WP Query on custom meta and sort by multiple meta keys value
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How can I made custom taxonomies relationship?
- What’s the WP way to load remaining custom posts?
- Custom taxonomies relationship
- Categorize custom post type
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- How to have this permalink structure: post_type/postname/custom_inner_page
- Query Custom Post Type Taxonomy term with multiple parameters
- First custom field value (out of several) displayed twice after query
- Using page title as a link to term archive
- WP_Query order custom post type with certain meta key value by post modified date
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Query custom posts from custom taxonomy
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Query Custom Post Type by Taxonomy
- Display featured posts for a custom post type by taxonomy
- Setup page template array in a custom post type
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- Related “custom post type” using “custom taxonomy”
- What is the most efficient way to execute recursive complex queries?
- 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
- How to get post count of specific taxonomy that have store name & category
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- Page that lists publications by classifying them by taxonomy
- custom taxonomy pagination 404 error
- Ordering by meta value not working
- Custom front-end form for adding post – Category problem
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Alike Shortcode using in Custom Shortcode
- Get all post under custom post type grouped by custom filed value in custom taxonomy
- Sort custom posts by date and then by taxonomy
- Query custom post type that has a serialized relational advanced custom field value
- have to do a while have post to show for two custom post types sharing the same taxonomy?
- Check that a slug is present in the get_terms request