2022 Developer Survey is open! Take survey.

Questions tagged [tax-query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
25 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
30 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
52 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
2 answers
29 views

Override tax_query with pre_get_posts to include other term_ids on a single category

I'm trying to include more than one term_id(multiple checkboxes filter) on a single category page. I managed to recollect enough to build a tax_query with pre_get_posts, but now it seems, I have two ...
user avatar
0 votes
0 answers
5 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
19 views

Get categories that has posts with a certain tag

I have a tag template where I list all the products based on category and tag combined. At the bottom of this page I want to show the visitor all the other categories that have products with the same ...
user avatar
1 vote
1 answer
11 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
0 votes
1 answer
26 views

Tax Query only returns for the first of several terms

I'm trying to query a customer post type where the results may be within one of several associated terms. The issue however is that only the first term yellow-gold-jewellery is being returned for, and ...
user avatar
  • 111
0 votes
0 answers
14 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
1 answer
42 views

How To Query For An Empty Taxonomy Field

I want to write a query that looks up taxonomies. One condition is that taxonomyA returns x, and a second condition is that taxonomyB returns empty. I don't know how to query for empty. This is what ...
user avatar
0 votes
0 answers
31 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
24 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
  • 1
0 votes
0 answers
44 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
174 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
33 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
803 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
2 answers
71 views

Tax query with multiple terms in pre_get_posts

I am trying to use a tax query in my pre_get_posts function. All is working but not when the array has multiple IDs. Let's say my URL looks like: ?listing_cat[]=1&listing_cat[]=2 Now I am trying ...
user avatar
  • 230
0 votes
1 answer
572 views

Adding a tax_query to a WP_Query Object

Is it possible to modify a WP_Query object to add a tax_query? That is -- I'm able to add a tax_query when instantiating a WP_Query object $q = new WP_Query(array( 'post_type' => 'post', '...
user avatar
0 votes
0 answers
115 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
63 views

Show posts from two specific category in WP_Query

I've two category employee and full-time. If a post publish in both (employee and full-time) category then the post will show in his specific section. If post has only employee category, not full-time ...
user avatar
0 votes
1 answer
38 views

I'm having trouble with Related Product "tax_query" 'terms' value

I have two custom page types. the first is "product" and the second is "accessories". On the product page, there is the accessories category "inputs" raleted post. Inputs ...
user avatar
0 votes
1 answer
259 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
92 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
38 views

How to remove term from wp_query in pre_get_posts?

I have a price range taxonomy setup for filtering. Taxonomy terms are like "20-50", "51-70", etc.. URL is mysite.com/products/price-range/21-50/ Products are setup with ACF to have ...
user avatar
0 votes
0 answers
15 views

"Invalid taxonomy" with WP_Query's tax_query [duplicate]

In WP_Query using tax_query to get products in categories, I recieve "invalid taxonomy" error. Doing that in my child theme. It seems as if WordPress hasn't loaded taxonomies yet in the ...
user avatar
0 votes
0 answers
31 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
152 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
1 answer
87 views

Is it possible to query posts with tax queries after multisite switch_to_blog() function?

On my newly installed multisite with 1 installed plugin ACF. And all code below is not being run though any filter or action and on the front end. On the front end in the page.php template, I can ...
user avatar
  • 422
1 vote
1 answer
235 views

Get list of terms that have posts in another term

I have a product attribute called "color" and when I am on the archive page (e.g. color=blue) I want to display a list of all the parent product categories that contain products with that ...
user avatar
  • 123
0 votes
0 answers
95 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
1 vote
1 answer
77 views

OR for a single taxonomy in a tax_query

I have a tax_query that has a value added like this: $query->query_vars['tax_query'][] = array( 'taxonomy' => 'location', 'include_children' => true, 'field' => 'county', '...
user avatar
0 votes
1 answer
43 views

Very complex post query

I need to create a very complex post query, but I don't know if such a query can exist, or if I have to write PHP code to combine the results of two different queries... Let me please describe the ...
user avatar
1 vote
1 answer
410 views

'wp' action hook not firing in admin and login?

I need to register an action via add_action('wp', function(){...}); The action works in frontend, but in backend and login page it doesn't work. It seems as if 'wp' hook doesn't exist for ...
user avatar
  • 141
1 vote
1 answer
193 views

Query custom post type by category slug

I'm trying to query a custom post type by its category slug, but its not working at all my custom post type definitions: add_action( 'init', 'custom_post_albuns' ); // The custom function to ...
user avatar
1 vote
1 answer
77 views

Meta Query relation “AND” not working

I want show (featured product) that instock, but this query just show in stock products. $query = array( 'post_type' => 'product', 'post_status' => 'publish', '...
user avatar
0 votes
1 answer
292 views

How to get rid of variations with unspecified attributes

Some of my products have these weird variations with unspecified attributes (I am using Size and Color in my store). It looks like this: So, if you would purchase a 85 B, Black variation of the ...
user avatar
1 vote
1 answer
172 views

Fetch posts that match term slug first two letters (wp query)

I want to fetch all posts whos terms matched the first two letters of the search letters. For example, I have terms 8027179, 8027180, 8247180. Now I want to assign letter 80 and fetch posts attached ...
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
  • 881
1 vote
1 answer
32 views

Taxonomy archive showing no results

I have the file taxonomy-project.php and am trying to view results for some of my terms. I keep getting a result of NO even though I have a post applied to that particular term. taxonomy-project.php &...
user avatar
0 votes
1 answer
206 views

How to exclude a taxonomy from shop & search page wooCommerce?

In my wooCommerce shop, I've 2 taxonomy 1. Product Category 2. Services Category Shop page is showing up all products from both categories. I want to exclude products from SHOP & Search Results ...
user avatar
0 votes
1 answer
1k views

WP_Query for a taxonomy value OR a custom post type meta field

I have a custom post type 'csl_playlist_manager', and one of its meta-fields is 'available_to_all'. I also have a custom hierarchical taxonomy, 'csl_source', which identifies the owner of each ...
user avatar
1 vote
1 answer
105 views

How to Filter custom post type by taxonomy?

here is my code trying to make it <div class="row"> <div class="col-lg-3 col-md-12"> <div class="card"> <div class="card-body&...
user avatar
0 votes
1 answer
53 views

tax_query will produce nothing

I want to display custom type posts from a custom taxonomy category so I did this: $news = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'news', 'tax_query' => array( ...
user avatar
  • 133
0 votes
0 answers
40 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
1 answer
702 views

Query with meta_query and tax_query together not working properly

I got some post in some categories { kids, man, woman } , and some ACF meta fields per country { Japan, South Korea ... }. If I query the categories with this tax_query it works perfectly: Array ( ...
user avatar
  • 121
1 vote
1 answer
191 views

Tax query clause inside a meta query clause?

I need to run the following query via a WP_Query object: SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ...
user avatar
  • 125
0 votes
0 answers
217 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
0 votes
1 answer
96 views

WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)

This is really confusing me. I've tried numerous things but cannot get appropriate results. Here's what I currently have for my query: $args = array( 'post_type' => 'product', 'tax_query'...
user avatar
  • 424
0 votes
1 answer
16 views

How to search through all child taxonomies using WP_Query?

I need to create a page in which I can search through child taxonomies(custom child-category) based on GET request (For example $_GET['search_cat']) using WP_QUERY. I just want to list all of the sub-...
user avatar
0 votes
1 answer
175 views

exclude product with available tag

I have classic WP_Querry: $products = new WP_Query( $args ); with $args = [ 'post_type' => 'product', 'posts_per_page' => 500, 'product_cat' => 'cars', ]; If I want products ...
user avatar

1
2 3 4 5 6