Languages: English • 日本語 (Add your language)
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.
Query vars are fed into WP_Query, WordPress' post querying API.
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.