Questions tagged [tax-query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3
votes
2answers
55 views

Does tax_query really beats meta_query in all situations?

Let me start saying that I know a 'tax_query' is faster than 'meta_query'. It's always recommended to use taxonomies over custom meta when filtering by custom data is required, but here I found ...
1
vote
1answer
9 views

tax_query returning all posts instead of selective posts in WP_Query

What I am trying to do Hi, in my site I have a custom post type called projects, then I have created a custom taxonomy for my projects post type called project_catagories. Now in my projects archive ...
0
votes
0answers
14 views

Query Multiple meta key values

I have a custom post type with 4 custom fields Participant (ayp_user) Event (ayp_event) Category (ayp_category) Total Score (ayp_score) I have set the following meta_query in a query. But it is ...
0
votes
1answer
34 views

list all post who have mutual taxonomy as current taxonomy!

I have app archive site with two different taxonomy type: Seller and Kind, I want to have a page for every seller and inside that page, I want to have multiple lists for every term of "Kind" taxonomy. ...
0
votes
1answer
19 views

Cannot get to work tax_query array for terms

I'm trying to pass an array to the terms parameter. Basically, I have a 'portfolio' custom post type where I need to get all the categories and pass them to the terms in order to only show that '...
0
votes
1answer
32 views

Why pagination is not working with tax_query param?

this is my query: $p_query = new WP_Query(array( 'post_type' => $post_type ,'post_status' => 'publish' ,'posts_per_page' => $per_page // 6 ,'paged' => $page // 2 ,'...
1
vote
1answer
52 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 ...
1
vote
0answers
20 views

?cat=-1 Indexed Versions Of Homepage

I'm finding some strange query strings on my homepage are indexed in Google and causing duplicate content. A couple of examples: https://sciencetrends.com/page/103/?cat=-1 https://sciencetrends.com/?...
1
vote
0answers
37 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 ...
0
votes
1answer
22 views

$query->is_main_query() is causing query's tax_query to be ignored

I was having issues when modifying the main query hooking onto pre_get_posts as it was causing the menu to not be displayed. This the original code: else if ( isset( $_GET['category'] ) && !...
0
votes
0answers
178 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 ...
1
vote
0answers
33 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 ...
0
votes
0answers
28 views

WordPress post_status and meta_query

I created a custom post status and I would like to set auto-change (clients are filling two dates, precomming and ongoing). How can I do auto-post-status change when it is after precomming or ongoing ...
-1
votes
1answer
13 views

How to pass >= condition filter to my year custom tax_query

I have a custom taxonomy called year. I need to filter posts by pre_get_posts tax_query from year value to to year value. I am searching from one hour now feeling stuck. Please guide me. Thank you
2
votes
1answer
46 views

get complex results set according to category structure

I need to get a complex result set from a WordPress database according to the category structure. First I will try to explain my category structure. I have three level structure as bellow. flight [...
0
votes
1answer
70 views

WP Query Conditionally query meta and taxonomy

I develop a plugin which includes a custom post type that is displayed as a list within WP Admin. There are varying levels of users defined within the plugin and a few other options which determine ...
0
votes
2answers
62 views

get_terms with posts that have a different taxonomy with term x

Here's the situation; I am using get_terms to retrieve all terms from Tax 1 with posts associated with it. Using the following $args = array( 'hide_empty' => 0, '...
0
votes
1answer
217 views

How to display Related Posts based on number of taxonomy terms matched

I have a custom post-type 'News' which has multiple custom taxonomies 'news-category', 'news-tags'. Each post contains between 4-8 'news-tags' and 1 'news-category'. For my current post, I'd like to ...
1
vote
2answers
609 views

How to create a WP_Query to search the Title or Tag?

I have created a search using WP_Query, it seems like this query is looking for the queried term in title AND tags. Is there a way to have this search the title OR tags? $s = $request['s']; $tags = ...
0
votes
0answers
18 views

how to display post of lowest terms - ancestors wise?

I want to achieve 3 post display from each taxonomy terms. But this terms will be passed from lowest of hierarchy in array that is ('munnar','cochin') etc. Europe Asia - India -- Kerala --- Munnar ---...
0
votes
1answer
100 views

Query child posts with tax query on parents

I have this WP_Query: new WP_Query( array( 'post_type' => 'product_variation', 'post_status' =&...
0
votes
1answer
147 views

How to set `tax_query` with `query->set()`

While this works: $query->set( 'post__not_in', array( 30140, 30020, 30008, 29998, 29991, 21458, 20197, 11986, 6614 ) ); This doesn't: $tax_query = array( 'taxonomy' => 'filter', 'terms' ...
0
votes
1answer
55 views

Custom Category Walker with Image, Fallback to Most Recent Post in Category Image

Based on this and this answer I am developing an extension of the Walker_Category which displays in image from an ACF field, falling back to the latest post's thumbnail. I have included the entire ...
0
votes
0answers
102 views

posts_per_page in a tax_query

I want to show two latest posts of a taxonomy in a front_page.php template. $args_article = array( 'post_type' => ['text'], 'post_status' => ['publish'], '...
0
votes
1answer
32 views

Custom search for a custom post type in WordPress

I have created a custom search for a custom post type in WordPress that searches car vehicles. I can search by manufacturer and model but I want the search to be flexible and show results based on any ...
0
votes
1answer
131 views

Nested tax_query that allows specified categories OR tags, but NOT other categories

I'm trying to create a nested tax query that does the following: Exclude posts that have any of several specified category IDs. AND include posts that have any of several other specified category IDs,...
0
votes
1answer
312 views

Find all product that contain terms with %keywords% in WP_Query

I want to use WP_Query to find all product terms entered in the input field. Here is my WP_Query code. $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( '...
0
votes
1answer
193 views

Get posts in taxonomy randomly

I am having a query like this Code 1 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $args = array( 'post_type' => 'l', 'post_status' ...
0
votes
0answers
31 views

All sticky posts are displaying on home.php and ignoring tax_query

I'm trying to query the main loop on my home.php template to display posts which are only in a specific taxonomy 'issue-41'. I'm using the pre_get_posts function to achieve this but when testing it, ...
1
vote
0answers
122 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 ...
0
votes
2answers
52 views

Loop posts based on permalink term

I have setup my custom post's custom taxonomy's permalink structure to be: custom post type > custom taxonomy > post (from this helpful Q&A) Now I'm hoping to be able to code taxonomy.php to ...
4
votes
1answer
828 views

pre_get_posts with tax_query causes empty result

I need to adjust the main loop for all archive pages in the following way. I have registered a custom taxonomy "myposttypes". Every single post is assigned to exactly one term of "myposttypes". If it ...
0
votes
2answers
239 views

How can I add multiple 'tax_query' arrays via a loop?

I'm trying to build functionality (using the Advanced Custom Fields plugin) to list information in a page template for all custom post types ('Product') that have specified taxonomies. This is my ...
1
vote
1answer
238 views

How to combine tax_query and date_query in Wordpress

I'm using the following query to extract all products which are not in the 'Service' product category and order them by a custom meta field '_vintage_age'. $q->set( 'tax_query', array(array( '...
1
vote
0answers
70 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)...
0
votes
1answer
210 views

Custom taxonomy query not working with switch_to_blog

Whats the wrong with this query? $args = array( 'category__not_in' => 1, 'post_status' => 'publish', 'numberposts' => 1, 'tax_query' => array( array( ...
0
votes
1answer
38 views

How can I get the last 5 element of this tax query?

$args = array( 'post_type' => 'news', 'posts_per_page' => 5, 'post_status' => 'publish', 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'week', '...
0
votes
0answers
51 views

Tax_Query not working - connecting to second wordpress database

I'm trying to run a WP_Query - using a second database, the connection and results work just fine until I use tax_query and then no results are returned: <?php $wpdb_backup = $wpdb; $wpdb =...
0
votes
0answers
43 views

tax_query not working?

tax_query is not working, inside the eachloop I'm trying to echo $use_case_category->slug; and getting all the taxonomies on the screen and not the ones selected by bootstrap tabs. All the rest of ...
1
vote
0answers
449 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, '...
1
vote
1answer
46 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 ...
2
votes
1answer
2k 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 ...
0
votes
2answers
38 views

Finding WordPress Posts assigned to multiple categories

I have a site with around 8000 products, with a slightly poor site structure - instead of custom taxonomies the Brand Name and Retailer are Parent Categories with the various individual brands, and ...
0
votes
1answer
31 views

Getting Custom Posts with Custom Taxonomy

I am trying to get the custom posts "contact" with the custom taxonomy "abteilung" for this post type. Everything i am trying is not working. Now i am stuck with the following. The problem is, that ...
1
vote
1answer
1k views

Tax query AND/OR meta query [duplicate]

In my WP_Query I'd like to have a tax query and a meta query, but I want the results to include results that match the tax query AND/OR the meta query - if I do it like the below, then it only returns ...
2
votes
0answers
41 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 ...
0
votes
1answer
158 views

Order Wordpress Query by Custom Field While Still Using Tax_query Argument

Currently, I have a query that searches for all employees with a taxonomy term that matches the word that is searched for in an input field. That works perfectly fine but my client now wants the ...
1
vote
0answers
188 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? ...
1
vote
1answer
787 views

pre_get_posts Remove tax_query if $_GET['tax']==all

I'm using pre_get_posts to filter by using $wp_query->set( 'tax_query', $tax_query ); I'm probably better-off doing this with a new WP_Query, but if someone knows something I don't I'd love to ...
1
vote
1answer
84 views

Get taxonomy parent using child slug (from merged taxonomies)

So, I tried a bunch of ways to do this, but none worked. I have an array, that has a lot of values from different taxonomies (from the same custom post type), I'm giving an example with only 2, but ...