Questions tagged [tax-query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
5
votes
1answer
2k views

Escaping WP_Query tax_query when term has special character(s)

Here's my issue. I have a custom post type that I'm attaching a custom taxonomy to. This taxonomy will allow the admin to provide search suggestions that will ensure the post is found when a user ...
1
vote
3answers
8k views

Wordpress tax query use operator LIKE

I have taxonomy color which is associated with a custom post type. I am listing all the post meta and the taxonomy in a table. I have a option in the table to search the posts matching the search ...
19
votes
3answers
46k views

Nested meta_query with multiple relation keys

I am curious whether Wordpress is able to run nested meta_query, with each having different relation keys? As of Wordpress 3.0, tax_query is able to perform this function; I'm wondering whether this ...
2
votes
1answer
1k views

Order posts by (hierarchical custom) taxonomy terms and term children

The scenario a custom post type wiki a (hierarchical) custom taxonomy topics a page template archive-wiki.php The situation Posts show up and get ordered by post_date (which is the default). The ...
3
votes
1answer
1k views

How to tax query X number of posts related by tag first, then by category if not enough in tag-related

Question How to output tag related posts first, then IF there are less than 4 tag related posts, fill the rest of the 4 spots with category related posts? Scenario Sometimes a post has very few ...
3
votes
2answers
4k views

When/why does '$query->get( 'tax_query' );' return empty?

First the code: function itsme_better_editions( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( 'post_type', array( 'post' ) ); ...
1
vote
2answers
1k views

if wp_query taxonomy term have posts

Having formulated my $query for a custom taxonomy on a page template, how would I ask if a specific term has posts? $args = array( 'post_type' => 'exhibitions', 'tax_query' => array( ...
7
votes
1answer
9k views

Wordpress tax_query “and” operator not functioning as desired

I have a custom post type of image with a custom taxonomy called image_tag (it's hierarchical like categories). Here are some examples of the tags that might be used: Structure (id: 25) - House (id: ...
2
votes
1answer
532 views

Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)

I have series of sorting issues on a page that I'm trying to figure out but so far to no avail. Sorting a list of CPT posts which are listed under associated custom taxonomy terms I found this piece ...
3
votes
1answer
9k views

Why is my WP_Query not working when tax_query terms are an array?

I have an issue with a WP_Query for a site I'm building which has me stumped. This works as expected: $package_args = array( 'post_type' =&...
2
votes
1answer
1k views

Query set using tax_query with relation 'OR' modifies category object?

(Update: Please see the edits far below.) The code: function itsme_better_editions( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( '...
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
3answers
2k views

Specify number of posts in my 'tax_query'

I'm showing posts of the term 'football' belonging to the taxonomy 'section', and everything works perfectly but Where can I specify the number of posts I want to show? just like this: 'showposts' =...
1
vote
0answers
48 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
1answer
599 views

Using tax_query reverses my post_type argument in a custom WP_Query

I'm using a custom query to pull some posts from a custom post type. I'm having problems with it so I used print_r on my WP_Query object and I found something strange. my query has these arguments: '...
1
vote
2answers
1k views

tax_query not working on main query

I'm using the following code to do a tax_query and it doesn't seem to work anymore.. At some point it was working and for the life of me it wont, anymore. <?php global $pf_override; class ...
1
vote
1answer
2k views

Problem with get_posts, tax_query and counting the number of posts

I want to count the number of posts that has simoultaneously 3 different taxonomies. THe code i'm using is this: $products = get_posts(array( 'post_type' => 'products', 'posts_per_page' =&...
1
vote
1answer
239 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
261 views

Count number of posts which exist in 2 taxonomies?

I know I can use something like this to count for ONE tax: $catcount=get_term_by('slug','apple', 'FRUIT'); echo $catcount->count; but not sure how to count posts that are in combos between ...
0
votes
3answers
3k views

Ordering Posts with Custom Taxonomy Terms Array

I can't get the order of my posts (organized by custom tax terms) to come out right in my loop. I made a custom post type of 'staff', in staff there is a custom taxonomy of 'staff-title'. I added ...
0
votes
1answer
95 views

How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts

Scenario I am using a complex, awesomely crafted tax query to get up to 4 related posts, first going by tag, then by category if there are not enough posts in tag-related query. This was finely ...
0
votes
0answers
1k 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: ...
-1
votes
1answer
366 views

Querying by taxonomy vs Querying by Custom fields Speed Comparison

I'm developing a listing portfolio for our project. (Basicaly yachts with their type, size, price, cabins, draft, build year, refit year etc.) I should filter them according to type and sort by (...