Questions tagged [tax-query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
142 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 ...
1
vote
2answers
439 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
996 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 ...
2
votes
2answers
2k 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
1answer
304 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
435 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
98 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
226 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
34 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
373 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,...
1
vote
1answer
880 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
353 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' ...
1
vote
0answers
167 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
127 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 ...
5
votes
1answer
2k 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 ...
1
vote
2answers
538 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
367 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
77 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
386 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
41 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
64 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
53 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
793 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
53 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
3k 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
39 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
2k 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
100 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
304 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 ...
2
votes
0answers
228 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
1k 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
100 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 ...
0
votes
1answer
81 views

Secondary WP_Query being overriden in archive page

I'm running into a particular problem with an archive page. This particular page is supposed to list all post that belong to a category, but is able to be filtered by a second (custom) taxonomy: i.e.: ...
1
vote
0answers
57 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. ...
1
vote
0answers
66 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 ...
1
vote
1answer
418 views

Tax_query not working on multisite

This query was working fine, but now i'm having a trouble with it since i've switched to multisite. I've added "global $switched" and "switch_to_blog(4)", and it works fine when i remove the "...
0
votes
1answer
2k views

How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?

I need to search property post types, in a regular WP_Query that is not the main query, but I need to be able to search for a value LIKE in any of the following meta_queries and also need to search ...
0
votes
1answer
413 views

Wordpress tax_query ignoring relation OR

Yo guys, I am writing related posts method and I am trying to get all posts that have one or more terms in one or more taxonomies. Here is the sample of what my function spits out: array( '...
1
vote
1answer
917 views

List taxonomy / category count showing list published posts only

I want to show on a list of taxonomy with corresponding posts counts of published items only. Checking the WP documentation, It seems I can ALMOST achieve that by using the get_terms function https://...
1
vote
1answer
2k views

Hidden woocommerce products still showing up in search results

I'm really new to php editing but I'm trying to learn. My woocommerce products that are set to "hidden" under catalog visibility are still showing up under search results. How do I keep hidden ...
1
vote
1answer
354 views

Querying on multiple taxonomies pulled from $_GET checkbox array not working?

I'll keep this super concise the normal search works perfectly, but when I've added some checkboxes for additional features, etc…the tax_query doesn't work however I know the $_GET is working as I've ...
0
votes
1answer
773 views

Optimal way to make tags in tax_query optional?

Is there a more elegant way of doing this same thing. I have three filters that I want to use to effect the results in the fourth field. The pool, month, and tags are the filters. I want the tags ...
0
votes
1answer
1k views

Is it possible to add relation between meta_query and tax_query?

I have custom post type with some ACF fields. I use ACF for extra properties of entity, and I use native wordpress taxonomies too for base category of entity. So I need to build query with meta_query ...
0
votes
3answers
814 views

WP Query tax_query not returning posts

I have a WP query that searches for any custom posts under type 'tribe_events' tagged as 'featured' under the taxonomy 'tribe_events_cat'. So, just to be clear: post_type = 'tribe_events' taxonomy = '...
0
votes
1answer
2k views

tax_query (if the terms are empty)

I'm confused, what do I pass in order to get all posts from all terms? Right now I can for instance pass featured in order to get all events, but how do I get all events? I know I could just get rid ...
1
vote
1answer
433 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 ...
0
votes
0answers
2k views

Combine tax_query and meta_query in WP_Query

I'm building a search in WordPress. I look for a custom_post_type in combination with several custom taxonomys and metadatas. custom_post_type: vehicle taxonomys: brand, fueltype, ... metadata: ...
0
votes
1answer
88 views

Complex Taxonomy scheme

We are building a resorts site and we're facing a huge taxonomy problem. On one side, we have administrative locations such as country>>region>>department and "natural" locations, such as mountain-...
1
vote
1answer
39 views

How do I display the grand child items of a taxonomy term?

I am trying to display the grand child terms for a custom taxonomy term. The main parent taxonomy term is product_range, the child taxonomy term is Mechanical Trackballs, each child category has ...