WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

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.

Query variables

Public 
  • attachment
  • attachment_id
  • author
  • author_name
  • cat
  • category_name
  • comments_popup
  • day
  • error
  • feed
  • hour
  • m
  • minute
  • monthnum
  • name
  • p
  • page_id
  • paged
  • pagename
  • post_parent
  • post_type
  • preview
  • second
  • static
  • subpost
  • subpost_id
  • tag
  • tag_id
  • tb
  • w
  • year
Private 
  • category__in
  • category__not_in
  • category__and
  • post__in
  • post__not_in
  • tag__in
  • tag__not_in
  • meta_key
  • meta_value


See this list:

$public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');

$private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');


via http://www.cleancode.co.nz/blog/731/post-data-wordpress-permalink-404

This list needs more work, if you have something to add go ahead.

This page is marked as incomplete. You can help Codex by expanding it.
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.