m (→Query variables) |
m |
||
(9 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | + | {{Languages| | |
+ | {{en|WordPress_Query_Vars}} | ||
+ | {{ja|WordPress_Query_Vars}} | ||
+ | }} | ||
− | + | Query vars define a query for WordPress posts. | |
− | + | When [https://codex.wordpress.org/Using_Permalinks ugly permalinks are enabled], query variables can be seen in the URL. For example, in the URL <tt>http://example.com/?p=1</tt> the <tt>p</tt> query var is set to 1, which will display the single post with an ID of 1. | |
− | + | When [https://codex.wordpress.org/Using_Permalinks pretty permalinks are enabled], URLs don't include query variables. Instead, WordPress transforms the URL into query vars via the [https://codex.wordpress.org/Rewrite_API Rewrite API], which are used to populate the query. | |
− | + | == Relationship to WP_Query == | |
− | + | Query vars are fed into [https://codex.wordpress.org/Class_Reference/WP_Query WP_Query], WordPress' post querying API. | |
− | + | == List of Query Vars == | |
− | |||
− | == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style="width:370px;float:left;padding:0;background:#f5f5f5;border:1px solid #ddd;margin-right:10px;"> | <div style="width:370px;float:left;padding:0;background:#f5f5f5;border:1px solid #ddd;margin-right:10px;"> | ||
Line 38: | Line 23: | ||
:* <tt>author</tt> | :* <tt>author</tt> | ||
:* <tt>author_name</tt> | :* <tt>author_name</tt> | ||
− | :* | + | :* <tt>cat</tt> |
− | :* | + | :* <tt>calendar</tt> |
+ | :* <tt>category_name</tt> | ||
:* <tt>comments_popup</tt> | :* <tt>comments_popup</tt> | ||
+ | :* <tt>cpage</tt> | ||
:* <tt>day</tt> | :* <tt>day</tt> | ||
:* <tt>error</tt> | :* <tt>error</tt> | ||
+ | :* <tt>exact</tt> | ||
:* <tt>feed</tt> | :* <tt>feed</tt> | ||
− | |||
:* <tt>hour</tt> | :* <tt>hour</tt> | ||
:* <tt>m</tt> | :* <tt>m</tt> | ||
:* <tt>minute</tt> | :* <tt>minute</tt> | ||
:* <tt>monthnum</tt> | :* <tt>monthnum</tt> | ||
+ | :* <tt>more</tt> | ||
:* <tt>name</tt> | :* <tt>name</tt> | ||
+ | :* <tt>order</tt> | ||
+ | :* <tt>orderby</tt> | ||
:* <tt>p</tt> | :* <tt>p</tt> | ||
:* <tt>page_id</tt> | :* <tt>page_id</tt> | ||
+ | :* <tt>page</tt> | ||
:* <tt>paged</tt> | :* <tt>paged</tt> | ||
:* <tt>pagename</tt> | :* <tt>pagename</tt> | ||
− | :* <tt> | + | :* <tt>pb</tt> |
:* <tt>post_type</tt> | :* <tt>post_type</tt> | ||
+ | :* <tt>posts</tt> | ||
:* <tt>preview</tt> | :* <tt>preview</tt> | ||
+ | :* <tt>robots</tt> | ||
+ | :* <tt>s</tt> | ||
+ | :* <tt>search</tt> | ||
:* <tt>second</tt> | :* <tt>second</tt> | ||
+ | :* <tt>sentence</tt> | ||
:* <tt>static</tt> | :* <tt>static</tt> | ||
:* <tt>subpost</tt> | :* <tt>subpost</tt> | ||
:* <tt>subpost_id</tt> | :* <tt>subpost_id</tt> | ||
− | :* | + | :* <tt>taxonomy</tt> |
− | :* | + | :* <tt>tag</tt> |
+ | :* <tt>tag_id</tt> | ||
:* <tt>tb</tt> | :* <tt>tb</tt> | ||
+ | :* <tt>term</tt> | ||
:* <tt>w</tt> | :* <tt>w</tt> | ||
+ | :* <tt>withcomments</tt> | ||
+ | :* <tt>withoutcomments</tt> | ||
:* <tt>year</tt> | :* <tt>year</tt> | ||
</div> | </div> | ||
Line 72: | Line 72: | ||
:* <tt>category__not_in</tt> | :* <tt>category__not_in</tt> | ||
:* <tt>category__and</tt> | :* <tt>category__and</tt> | ||
+ | :* <tt>comments_per_page</tt> | ||
+ | :* <tt>offset</tt> | ||
+ | :* <tt>perm</tt> | ||
:* <tt>post__in</tt> | :* <tt>post__in</tt> | ||
:* <tt>post__not_in</tt> | :* <tt>post__not_in</tt> | ||
+ | :* <tt>post_mime_type</tt> | ||
+ | :* <tt>post_parent__in</tt> | ||
+ | :* <tt>tag__and</tt> | ||
:* <tt>tag__in</tt> | :* <tt>tag__in</tt> | ||
:* <tt>tag__not_in</tt> | :* <tt>tag__not_in</tt> | ||
+ | :* <tt>tag_id</tt> | ||
+ | :* <tt>tag_slug__and</tt> | ||
+ | :* <tt>tag_slug__in</tt> | ||
:* <tt>meta_key</tt> | :* <tt>meta_key</tt> | ||
:* <tt>meta_value</tt> | :* <tt>meta_value</tt> | ||
</div> | </div> | ||
− | |||
− | + | <br class="clear"> | |
+ | |||
+ | == 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, | ||
− | + | <pre> | |
+ | <?php | ||
− | + | $query = new WP_Query(array( | |
+ | 'post__in' => array(3, 7) | ||
+ | )); | ||
+ | </pre> | ||
− | + | works, but visiting <tt>http://example.com/?post__in=3,7</tt> would not work. | |
− |
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.