Questions tagged [tax-query]

The tag has no usage guidance.

95 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2 votes
2 answers
2k views

Change default ordering of taxonomy terms - pre_get_terms

I wanted to change the default taxonomy terms order by its 'term_order' value instead of 'name' in admin side. So I tried something like below. But it doesn't work and php memory exhaust. function ...
user avatar
  • 203
2 votes
0 answers
4k views

Woocommerce change tax rate programmaticly

We sell a combination of multiple products as one product, these products can't be added separte to WordPress so we use a normal product type for the combination. These products have seperate tax ...
user avatar
2 votes
1 answer
4k views

Display related products with custom output

I'm trying to display the related products with my custom html output, unfortunately i'm kind of lost on how to do this. The WP_Query below displays the products that are in stock, what i want is to ...
user avatar
2 votes
0 answers
176 views

Can't make a tax_query across different post types

I am attempting to build a tax_query, and I'm unable to make it behave. What I want to retrieve from the query are two different content types: A) Posts that are in a specific Category B) Portfolio ...
user avatar
  • 807
2 votes
0 answers
363 views

WP_Query with tax_query, order by most 'matches'

TL;DR: How can I sort a WP_Query based on how many 'matches' there are on the tax_query set. Furthermore, how can I then add more posts if the posts_per_page is not met due to the tax_query added? ...
user avatar
  • 21
2 votes
0 answers
947 views

tax_query OR with empty result returns all posts

I'm running a WP_Query with a tax_query with two tax_query statements with an OR relationship. $tax_query_terms = array( array('taxonomy' => 'post_tag', ...
user avatar
  • 336
2 votes
1 answer
2k views

How do I sort posts by custom taxonomy?

I am trying to sort posts by custom taxonomy. I have a custom post type which is course-cpt and I have created custom taxonomies within it, I need to sort the courses by course-level (which is the ...
user avatar
1 vote
1 answer
20 views

Fastest way of counting posts of a custom post type in a specific taxonomy term?

I know this kind of question is legion but I have read through all related topics and I can't find a satisfying solution. What I want to achieve is simple: on my taxonomy (author) term archive page I ...
user avatar
1 vote
0 answers
18 views

Manipulate WP Query using a custom post type and multiple tax_query taxonomies

I'm using the template_redirect action to hook into my archive page before and after the query using $_GET params for 2 different taxonomies. One for GAME and another for MODES. The query works ...
user avatar
1 vote
0 answers
44 views

Is it a good idea to improve meta query performance by adding tax query?

I'm aware that using taxonomies over metadata is preferred when it comes to posts grouping. In simple words this and this are saying "use meta for unique data and taxonomy for repeating data(the one ...
user avatar
1 vote
1 answer
403 views

Custom post taxonomies as tax_query terms?

I have these two custom post types called “product” and “reference”. On “references” I have attached a custom taxonomy called “product_reference” which I use to specify which products the references ...
user avatar
  • 11
1 vote
0 answers
50 views

WP_Query | Tax_Query Relation | Unable to use 'OR' as it then allows all products, help me finish my query?

I began slightly baffled and have slowly degraded to slightly going insane as I am building this wp_query. Admittedly it is a very complex query and there is a lot of additional code that has brought ...
user avatar
1 vote
1 answer
663 views

WP_Query tax query part of slug

I have problem with filtering post with tax query. I have a custom taxonomy called 'actors' and example of the slug is 'david-hasselhoff'. The problem is the post is found when I search with 'david ...
user avatar
1 vote
0 answers
209 views

Searching in title or meta, with a tax query too!

As suggested in WP Query Args - Title or Meta Value I tried to query my Custom Content Type on Title and Meta Value alternatively. It almost works, but only if I do not introduce a tax query (and I ...
user avatar
1 vote
0 answers
38 views

Taxonomy Query Relation field not behaving correctly?

This is my post entries with categories and tags I am using Taxonomy query When I use relation AND - Tax Query for Category Geed + Tag Cool Nothing shows up. But When I use relation OR 2 The post ...
user avatar
1 vote
0 answers
200 views

Tax Query for custom Taxonomy field

I have a stock filter on WooCommerce shop page. So I need to filter number of products based on the selection from the user for this filter. I have variable products and I am not able to control ...
user avatar
  • 313
1 vote
0 answers
397 views

Tax query in pre_get_posts not working

I'm trying to filter the main query on the home.php template so I only shows posts from the latest issue taxonomy. What I have so far is the below but it is still showing all the posts on the ...
user avatar
  • 154
1 vote
0 answers
78 views

Why is this query not working? (Standard posts + custom post type)

I'm trying to figure out why this query is not working, as it seems like it should be very straightforward. Basically, I'm querying for both standard posts of certain categories (and excluding another)...
user avatar
  • 217
1 vote
0 answers
1k views

Using meta_query and tax_query at the same time

I’ve got the following query on my page template: $args = array( 'post_type' => 'givingback', 'post_status' => 'publish', 'posts_per_page' => 100, '...
user avatar
1 vote
1 answer
85 views

Retrieve Custom Taxonomies according to posts selected

I have 3 custom taxonomies. The first 2 are for car make and model, the 3rd is for car series. The goal is make a widget which lists car series' depending on current post (make and model). function ...
user avatar
1 vote
0 answers
66 views

Terms with more than one occurrence have current-menu-item class in menu

I have a lot of taxonomies and I am using one term (from any of the taxonomies) in more than one place in my menu. I want to implement a post loop which depends on the menu id and all its parent ids. ...
user avatar
  • 313
1 vote
0 answers
84 views

More then one menu items are assigned with "current-menu-item" class

I am new with WordPress so apologize if i am doing this in a wrong way. I have lot of taxonomies and posts types. I am using one term (from any of the taxonomy) in more then one places in my menu but ...
user avatar
  • 313
1 vote
1 answer
689 views

Custom Widget WP_Query problem

I have everything working on my widget except the results! I created a taxonomy called country names that we use for several custom post types. I created this widget to display tour guides (CPT) from ...
user avatar
1 vote
0 answers
3k views

How can I hide uncategorized products from search results?

I'm trying to hide products that are not in any category (product_cat) from the search results. I've been trying to figure out how I could modify the search query to exclude these products, but I can'...
user avatar
1 vote
0 answers
274 views

Custom Taxonomy Not Working When added to WordPress Search

I have created custom taxonomies for a custom post type. I have added drop downs to the search form so I can add the custom taxonomies to the search criteria. The problem I am having is that when my ...
user avatar
  • 31
1 vote
0 answers
257 views

Wordpress tax_query not showing private posts

When querying posts with the following: $getClientsArgs = array( 'post_type' => 'client', 'showposts' => -1 ); query_posts($getClientsArgs); Private posts are displayed if the person ...
user avatar
1 vote
1 answer
612 views

Hiding taxonomies with no children WP_Query & tax_query

I have this code which has taken over 7 hours to put together through research but the last hours or so I have hit a brick wall! I require the taxonomy title to be hidden if there are no posts ...
user avatar
1 vote
0 answers
93 views

Exclude posts which have any term in a certain taxonomy from the query

I have a custom taxonomy, and for a certain query I am doing, I want to retrieve all posts which do not have any terms of that taxonomy assigned (for example, they are tag-less). At the beginning I ...
user avatar
0 votes
0 answers
17 views

"Menu order" being ignored when querying posts from a parent taxonomy with "include_children" set to true

I have a CPT of articles and a custom taxonomy of collection. This is how the articles are assigned to the collections: Collection 1 Article 1 (menu_order = 1) Article 2 (menu_order = 2) Sub ...
user avatar
0 votes
0 answers
25 views

Custom Query: Multiple CPTs and a taxonomy filter

I want to create a post feed that displays the following: ALL posts in the CPT 'custom_post_type_1' Any 'post's in the category 'speakers' So far, I have this filter which displays all posts in '...
user avatar
  • 1
0 votes
0 answers
16 views

Hi need update in my terms for other taxonomy

I'm new to wordpress, and in this case I created 2 taxonomies, cat_notice and trash_notice, what I need to do is when I delete a term, instead of it being deleted, it is reinserted in another taxonomy ...
user avatar
0 votes
1 answer
52 views

Order WP_Query by The Order of an Array in Tax_Query

I have a wp_query that uses tax_query to which I pass an array of taxonomy term IDs. I'd like to order my results based on the order of that array but can't get it to work and searching has got me ...
user avatar
  • 11
0 votes
0 answers
33 views

Any quicker alternative for WP_Query "NOT IN"

I am using the following wp_query to pull up a list of post, and I want to exclude a few categories of a custom taxonomy. It works well, however Query Monitor is telling me that the query is slow. I ...
user avatar
  • 123
0 votes
0 answers
189 views

Tax Query on product_cat using NOT IN as operator does not exclude that category

Using the following code, I expect $items to not include products with the product category "stones." However, that is not the result. It doesn't seem to be excluding that category at all. ...
user avatar
0 votes
0 answers
7 views

List only parent attributes on woocommerce admin atrributes page

I would like to add option on attributes page screen options, to filter out only parent attributes. The main struggle is that I can't even alter the query... I tried actions: parse_query, ...
user avatar
  • 296
0 votes
0 answers
22 views

Get Posts Related to Category By category id or slug

I used tax query to get it $term = get_queried_object(); $args = array( 'post_type' => 'portfolio', 'tax_query' => array( array( 'taxonomy' => 'categories', ...
user avatar
0 votes
0 answers
53 views

How do I make these combination select filters work when only one dropdown is set? They work in Wordpress 5.8.2 but don't in 5.8.3

I have a custom post type: 'insight'. I have 5 custom taxonomies: insight_service, insight_type, insight_month and insight_year. I'm using a form with select dropdowns dynamically filled with the ...
user avatar
0 votes
0 answers
27 views

problem with setting tax_query in pre_get_posts

I tried to make an advanced search which shows posts in a custom post type (book) with custom taxonomy (writer) that user wants. This code works in a query in a page but didn't work in pre_get_posts. ...
user avatar
  • 11
0 votes
0 answers
45 views

Display just the Post's parent Category, not child

I want to display all post under a parent category (custom taxonomy) ONLY!. Here's what I've done so far:' <?php $args_1 = array( 'fields' => 'ids', ); $custom_taxterms = ...
user avatar
0 votes
0 answers
227 views

AJAX not working when clicking load more button, when two terms are present in tax_query

I have inherited a project using a child theme based on the Avada theme. The previous developer has created a plugin to add custom elements to the Avada fusion builder. One of those elements, the ...
user avatar
0 votes
0 answers
38 views

Facing problem with tax_query results

I need to get search results for posts on the basis of post-category(must) and posts-tags(optional). The process is like: search for a string e.g. "bananas" the category is always static ...
user avatar
0 votes
0 answers
1k views

PHP Warning: Attempt to read property "slug" on bool in tax query

In the tax_query, I have used the 'term' = array( $category->slug ). I'm getting an error notice where using $category->slug, however, in the frontend it displays the slug of the term. Please ...
user avatar
  • 13
0 votes
0 answers
141 views

Get products under their custom taxonomy term

Hi guys i've create a custom taxonomy called level to show the complex of a course in woocommerce, what i try to do is show the term and under them the last 3 products for example Term 1 Product 1 ...
user avatar
  • 9
0 votes
1 answer
332 views

Display related CPT with custom taxonomy

I have two custom post types: "storefront_location" and "services" These are linked by a custom taxonomy "location" I am building a post template for "...
user avatar
  • 1
0 votes
0 answers
96 views

WP Query should show No Posts when tax_query $args taxonomies don't have associated posts

I have a simple query. Getting the posts only if it have both the taxonomies in it. $args = array( 'post_type' => 'treatment', 'tax_query' => array( '...
user avatar
  • 11
0 votes
0 answers
34 views

Multiple dynamic Tax Query - pass taxonomy argument from array

I need to make a multiple dynamic tax query $args['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => $taxonomies, 'field' =&...
user avatar
  • 23
0 votes
0 answers
171 views

Tax query get first product with attribute value in pre_get_posts

We've got a webshop with over 3000 products. Some products have the same attribute value for pa_model, as shown below. Productid 1 - pa_model Nike Productid 2 - pa_model Nike Productid 3 - pa_model ...
user avatar
  • 9
0 votes
0 answers
115 views

custom post type and a "sticky" position taxonomy

I have a custom post type with a custom taxonomy that denotes various types of places the custom post might appear in the site. One that I'm having some trouble with is a "sticky" term for ...
user avatar
  • 472
0 votes
0 answers
44 views

Can I create a tax query to return posts that match two slugs from same taxonomy

What I'm trying to achieve: I have a taxonomy 'module_data' which is hierarchical. What I want is to use a tax query to get all posts that match a slug in an array of slugs for terms AND also match a ...
user avatar
  • 139
0 votes
0 answers
229 views

wp_query with meta_query and tax_query

I am trying to find a way to combine a meta_query and a term_query and i got confused with the research. $sport = 'basket'; $args_p = array( 'posts_per_page' => 10,...
user avatar
  • 1