//Free AI Tools
->

WP_Term_Query Admin

Beta

WP Term Query Generator

Generate WordPress term queries to filter and display content based on taxonomy terms such as categories, tags, or custom taxonomies.
AI auto_awesome

CodeWP's AI will process this text and return the AI output. It will not account for other settings in the form, so be specific. Max words 60. AI Disclaimer

General Settings

Assign a unique name for this query for identification, like 'product_categories_query'.

Specify the taxonomy from which to retrieve terms. For example, 'category', 'post_tag', or any custom taxonomy name.

Filtering Options

Filter terms by their exact name. Useful for retrieving a single term.

Filter terms by their slug. This is helpful for retrieving terms with known slugs.

Perform a free-text search within terms. This will match terms based on your search criteria.

Retrieve terms that have names similar to the specified value. This is a partial match search.

Search for terms with descriptions that partially match the given string.

Inclusion and Exclusion

Specify term IDs to include in the results. Can be a single ID or a comma-separated list of IDs.

Specify term IDs to exclude from the results. Use this to omit specific terms.

Enter term IDs to exclude entire term trees. Useful for omitting parent terms and all their children.

Hierarchical Settings

Filter terms by parent ID. Use '0' to only include top-level terms.

Retrieve terms that are children of the specified term ID.

Whether to include terms that have non-empty descendants (even if 'hide_empty' is set to true).

Set to true to only retrieve terms that have no children.

Advanced Options

Limit the number of terms to retrieve. Set to '-1' for all terms.

Skip a set number of terms before returning results.

Designates the ascending or descending order of the 'orderby' parameter. Options: 'ASC' (ascending) or 'DESC' (descending).

Sort retrieved terms by parameter. Options: 'name', 'slug', 'term_group', 'term_id', 'id', 'description'.

Whether to hide terms not assigned to any posts.

Specify fields to return. Use 'all' for all fields or 'ids' for term IDs.

Whether to return a term count (without setting 'fields').

Unique cache key to distinguish the query cache from others.

Whether to update the term meta cache.

Visitor Features (Login/Register)
<?php

How To Use This Tool

1. Define Your Settings
Use our Structured form to modify the code you're about to generate.
Watch A Demo →
2. Or Prompt Our AI
Alternatively, you can prompt our AI to do this for you.
Learn More About Prompting →
3. Copy code and Install
Click the generate code button, copy it, and install it on a testing website.
How To Test Code →

More Info About WP_Term_Query

The WP_Term_Query generator tool allows you to easily generate custom queries to retrieve WordPress taxonomy terms based on specific criteria. This tool is perfect for site administrators and developers who need to filter terms such as categories, tags, or custom taxonomies without manually writing SQL queries.

Use our AI-driven interface to craft complex term queries or select from preset options for quick query generation.

Getting Started

  1. Configure Term Query Settings: Use the form below to define criteria like taxonomy name, term IDs, or meta data.
  2. AI-Powered Query Generation: Describe your desired query, and let our AI build it for you.
  3. Copy & Implement: Once your query is ready, copy the generated PHP code and paste it into your custom plugin or theme.

Query Configuration

Query Variable Name
my_term_query
Define a unique variable name for your query to prevent conflicts with other queries.

Basic Parameters

Taxonomy
Select the taxonomy you want to filter by (e.g., category, post_tag, product_cat).

Term IDs
Specify the term IDs you want to filter by (e.g., 1, 2, 3). The tool will include only terms that match the selected IDs.

Include Empty
Choose whether to include empty terms in the query result.

Advanced Parameters

Meta Query
Filter terms based on specific metadata, such as a custom meta key and value.

Query Output

$args = array(
'taxonomy' => 'category',
'include' => array(1, 2, 3),
'meta_query' => array(
array(
'key' => 'featured',
'value' => 'yes',
'compare' => '='
),
),
);
$term_query = new WP_Term_Query( $args );

More Info About WP_Term_Query

The WP_Term_Query class allows you to query WordPress taxonomy terms efficiently. You can retrieve terms by taxonomy, term IDs, metadata, and more. This tool simplifies complex term queries, helping you avoid writing manual SQL.

WP_Term_Query Admin FAQs

What is WP_Term_Query?

WP_Term_Query is a WordPress class that allows you to query taxonomy terms like categories, tags, or custom taxonomies.

Can I filter by multiple term IDs?

Yes, you can filter by multiple term IDs by providing an array of IDs in the query.

What is the include_empty parameter for?

The include_empty parameter controls whether to include taxonomy terms that have no associated posts or content.

Can I filter terms by metadata?

Yes, you can filter terms based on custom metadata by using the meta_query parameter.

How do I copy and implement the query?

After generating your query, copy the PHP code and paste it into your theme or plugin to retrieve the desired taxonomy terms.

What is the difference between WP_Tax_Query and WP_Term_Query?

WP_Tax_Query filters posts based on taxonomy terms, while WP_Term_Query directly retrieves taxonomy terms themselves.

Related AI Tools & Generators

Make WordPress Easy With AI
© WPAI, Inc. 2024 | d.b.a CodeWP
cross