The WP_Tax_Query generator tool allows you to easily generate custom queries to filter and display WordPress posts based on taxonomy criteria. This tool is ideal for site administrators and developers who need to retrieve posts based on terms, taxonomy relations, and complex taxonomies without manually writing SQL queries.
Use our AI-driven interface to craft complex taxonomy queries or select from preset options for quick query generation.
Getting Started
Query Variable Name
my_tax_query
Define a unique variable name for your query to prevent conflicts with other queries.
Taxonomy
Select the taxonomy you want to filter by (e.g., category
, post_tag
, product_cat
).
Terms
Specify the terms you want to filter by (e.g., books
, electronics
). The tool will include only posts that belong to the selected terms.
Field
Choose the field to filter by, such as slug
, name
, or term_id
.
Operator
Select an operator to define how terms are compared, such as IN
, NOT IN
, AND
, or EXISTS
.
Relation
Choose whether multiple taxonomies should be related with AND
(all conditions must match) or OR
(any condition can match).
Include Children
Specify whether child terms of hierarchical taxonomies should be included. For example, if a parent term is selected, its child terms will also be included.
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array('books', 'electronics'),
'operator' => 'IN',
'include_children' => true,
),
),
);
$tax_query = new WP_Query( $args );
The WP_Tax_Query
class allows for advanced filtering of posts in WordPress based on taxonomy terms. You can filter posts by categories, tags, and custom taxonomies. Here’s a basic example of querying posts by taxonomy:
You can also combine multiple taxonomy queries using relation
to create complex filtering rules.
This tool simplifies the process of constructing complex taxonomy queries without needing deep knowledge of WordPress's taxonomy query API. You can quickly generate tax queries, saving time and avoiding errors.