Codex

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

WordPress Query Vars

Query vars define a query for WordPress posts.

When ugly permalinks are enabled, query variables can be seen in the URL. For example, in the URL http://example.com/?p=1 the p query var is set to 1, which will display the single post with an ID of 1.

When pretty permalinks are enabled, URLs don't include query variables. Instead, WordPress transforms the URL into query vars via the Rewrite API, which are used to populate the query.

Relationship to WP_Query

Query vars are fed into WP_Query, WordPress' post querying API.

List of Query Vars

Public 
  • attachment
  • attachment_id
  • author
  • author_name
  • cat
  • calendar
  • category_name
  • comments_popup
  • cpage
  • day
  • error
  • exact
  • feed
  • hour
  • m
  • minute
  • monthnum
  • more
  • name
  • order
  • orderby
  • p
  • page_id
  • page
  • paged
  • pagename
  • pb
  • post_type
  • posts
  • preview
  • robots
  • s
  • search
  • second
  • sentence
  • static
  • subpost
  • subpost_id
  • taxonomy
  • tag
  • tag_id
  • tb
  • term
  • w
  • withcomments
  • withoutcomments
  • year
Private 
  • category__in
  • category__not_in
  • category__and
  • comments_per_page
  • offset
  • perm
  • post__in
  • post__not_in
  • post_mime_type
  • post_parent__in
  • tag__and
  • tag__in
  • tag__not_in
  • tag_id
  • tag_slug__and
  • tag_slug__in
  • meta_key
  • meta_value


Public vs. Private query vars

Public query vars can be used in the URL querystring. Private query vars cannot.

Private query vars can only be used when creating a query in PHP. For example,

<?php

$query = new WP_Query(array(
	'post__in' => array(3, 7)
));

works, but visiting http://example.com/?post__in=3,7 would not work.