Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [tax-query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
132 views

Querying by post category slug with core/query block markup

I know how to query all posts in a certain category by slug with WP_Query. What I would like to do is the same with the core/query block markup. I am able to get it working with the category ID, but I'...
JDQ's user avatar
  • 149
1 vote
0 answers
7 views

Same query args showing different results order when setting different number of posts

This query using the same arguments is returning different posts order: sample / test codes: // Query 1 $query_args = [ 'post_type' => 'business', 'showposts' => 8, 'no_found_rows' =&...
FatMiming's user avatar
0 votes
0 answers
23 views

Tax query: exclude posts if ONLY a certain term is applicable

Say I have this tax query: function add_tax_query( $args, $atts ) { $args['tax_query'][] = array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', ...
Guido Goluke's user avatar
0 votes
1 answer
69 views

Operator 'AND' in the get_posts() function's tax_query terms not working

I am trying to get posts that are present in both the taxonomy terms. This is the code that didn't work: $args = array( 'post_type' => 'workshops', 'posts_per_page' => -1, 'fields' =...
user1448031's user avatar
2 votes
1 answer
642 views

Custom query with custom filtering returning incorrect results

I've setup a custom query, I'm using Woocommerce and I am aware that it has it's own functionality, but have been tasked with creating custom filtering with a traditionally paged product/category ...
Bagseye's user avatar
  • 69
0 votes
1 answer
216 views

wp_get_object_terms count on taxonomies within an category archive

Working on a category archive, i have a sidebar with custom non hierarchical taxonomies, used as filters (like custom post_tags). In order to list those filters, I use wp_get_object_terms: <?php ...
rafa226's user avatar
  • 121
0 votes
0 answers
265 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 '...
srack's user avatar
  • 1
0 votes
1 answer
751 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 ...
shagpun's user avatar
  • 11
0 votes
0 answers
111 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 ...
Edegist's user avatar
  • 133
0 votes
0 answers
961 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. ...
the.s.brom's user avatar
1 vote
2 answers
792 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 ...
steakoverflow's user avatar
3 votes
1 answer
447 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 ...
Julien G's user avatar
0 votes
1 answer
351 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 ...
jmcgrory's user avatar
  • 111
0 votes
1 answer
456 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 ...
iwillbeawebdeveloper's user avatar
0 votes
0 answers
78 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. ...
ali's user avatar
  • 11
0 votes
0 answers
49 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 = ...
Mateusz Mati's user avatar
0 votes
0 answers
859 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 ...
mspacecreative's user avatar
0 votes
0 answers
120 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 ...
Majid A.'s user avatar
0 votes
0 answers
4k 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 ...
praba's user avatar
  • 13
0 votes
2 answers
787 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 ...
RobbTe's user avatar
  • 242
1 vote
1 answer
4k 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', '...
Alana Storm's user avatar
0 votes
1 answer
424 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
52 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 ...
onurtrkylmaz's user avatar
0 votes
1 answer
673 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 "...
srack's user avatar
  • 1
0 votes
0 answers
139 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( '...
Joy's user avatar
  • 31
0 votes
0 answers
16 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 ...
hbokmann's user avatar
0 votes
0 answers
48 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' =&...
Gozer's user avatar
  • 23
0 votes
0 answers
299 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 ...
Theo's user avatar
  • 9
0 votes
1 answer
265 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 ...
joshmoto's user avatar
  • 447
1 vote
1 answer
876 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 ...
Edegist's user avatar
  • 133
0 votes
0 answers
460 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 ...
jshwlkr's user avatar
  • 512
1 vote
1 answer
420 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', '...
Rando Hinn's user avatar
0 votes
1 answer
56 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 ...
James B.'s user avatar
1 vote
1 answer
1k 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 ...
dodo254's user avatar
  • 151
1 vote
1 answer
1k 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 ...
Cello Nascimento's user avatar
1 vote
1 answer
375 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', '...
och's user avatar
  • 39
0 votes
1 answer
1k 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 ...
Kristián Filo's user avatar
1 vote
1 answer
625 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 ...
Jamil Ahmad's user avatar
1 vote
0 answers
47 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 ...
Laurence Tuck's user avatar
1 vote
1 answer
293 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
494 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 ...
Danish Mohammed's user avatar
0 votes
1 answer
3k 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 ...
Wayne McHugh's user avatar
1 vote
1 answer
1k 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&...
ialyzaafan's user avatar
0 votes
1 answer
263 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( ...
Cain Nuke's user avatar
  • 163
0 votes
0 answers
100 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 ...
Eujinks's user avatar
  • 139
2 votes
1 answer
2k 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 ( ...
Fabman's user avatar
  • 141
1 vote
1 answer
441 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 ...
superfive33's user avatar
0 votes
0 answers
275 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,...
Kap40's user avatar
  • 1
0 votes
1 answer
788 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'...
bbruman's user avatar
  • 464
0 votes
1 answer
105 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-...
Appolonias's user avatar

1
2 3 4 5 6