WordPress Query Vars

Contents

Query Vars

An array of query vars are available for WordPress users or developers to utilise in order to query for particular types of content or to aid in theme and/or plugin design and functionality.

Public query vars are those available and usable via a direct URL query in the form of.

example.net/?var1=value1&var2=value2

Private query vars cannot be used in the URL, although WordPress will accept a query string with private query vars, the values will not be passed into the query and should be placed directly into the query. An example is given below.

query_posts('privatevar=myvalue');

Note: Query vars are not necessarily the same thing as query args in URLs (e.g., add_query_arg( 'foo' ). Query vars should only be registered for parameters that actually affect the behavior of WP_Query, and not just for any value passed in the URL. See #16373 for details.

Query Examples

Custom post types and taxonomies can also be queried publicly.

Query Post Type

example.net/?post_type=value1

In this example, value1 would be the post type slug you want to query. This would return all posts that match the specified post_type slug.

Query Custom Taxonomy

example.net/?tax1=term1

In this example, tax1 is the taxonomy slug and term1 is the term within that taxonomy that you would like to look up. This would return all posts (regardless of post_type) matching that taxonomy term.

Queries combining multiple values can be combined to form more complex, granular queries. For instance, to find only posts of a given post type AND taxonomy term, you can specify both.

This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.