Taxonomy Queries

Taxonomies are tools for organizing content in WordPress. Categories and tags are built-in taxonomies, and you can create additional taxonomies. Use the parameters below to query based on taxonomy terms.

taxonomy
The taxonomy you would like to query

tax_term
The term (or terms) you would like to include

tax_operator
Operator to test. Possible values are ‘IN’, ‘NOT IN’, ‘AND’, ‘EXISTS’ and ‘NOT EXISTS’. Default value is ‘IN’.

tax_include_children
Whether to include posts in the subcategories of the categories you’ve specified. Default value is true.

To display posts with either the “blue” or “green” terms in the “color” taxonomy:

[display-posts taxonomy="color" tax_term="blue, green"]

To display posts with both “blue” and “green” terms:

[display-posts taxonomy="color" tax_term="blue, green" tax_operator="AND"]

Multiple taxonomy queries

While most people will only ever need a single taxonomy query, this plugin supports an infinite number of taxonomy queries. Let’s say you wanted to get all posts in category “featured” and also tagged “homepage”. We’ll use a shortcode that looks like this:

[display-posts taxonomy="category" tax_term="featured" taxonomy_2="post_tag" tax_2_term="homepage"]

You can string as many of those as you like, just start the count at 2. In the field listing below, replace (count) with an actual number.

Here’s the available fields:

taxonomy_(count)
Which taxonomy to query
Default: empty

tax_(count)_term
Which terms to include (if more than one, separate with commas)
Default: empty

tax_(count)_operator
How to query the terms (IN, NOT IN, or AND)
Default: IN

tax_(count)_include_children
Whether to include posts in the subcategories of the categories you’ve specified.
Default: true

tax_relation
Describe the relationship between the multiple taxonomy queries (should the results match all the queries or just one of them). Available options: AND and OR
Default: AND

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.