-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.html
329 lines (301 loc) · 44.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<html lang="en-US"><head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Begin Jekyll SEO tag v2.5.0 -->
<title>WordPress Query Comprehensive Reference | wp-query-ref</title>
<meta name="generator" content="Jekyll v3.7.3">
<meta property="og:title" content="WordPress Query Comprehensive Reference">
<meta property="og:locale" content="en_US">
<meta name="description" content="WordPress Query Comprehensive Reference">
<meta property="og:description" content="WordPress Query Comprehensive Reference">
<link rel="canonical" href="https://luetkemj.github.io/wp-query-ref/">
<meta property="og:url" content="https://luetkemj.github.io/wp-query-ref/">
<meta property="og:site_name" content="wp-query-ref">
<script type="application/ld+json">
{"name":"wp-query-ref","description":"WordPress Query Comprehensive Reference","@type":"WebSite","url":"https://luetkemj.github.io/wp-query-ref/","headline":"WordPress Query Comprehensive Reference","@context":"http://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<style class="anchorjs"></style><link rel="stylesheet" href="style.css?v=d1b24a27925c67170b2f6443a2de7fe8fedcb5f7">
</head>
<body>
<div class="container-lg px-3 my-5 markdown-body">
<h1><a href="https://github.com/luetkemj/wp-query-ref">⏪ wp-query-ref</a></h1>
<h1 id="wordpress-query-comprehensive-reference">WordPress Query Comprehensive Reference</h1>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?php</span>
<span class="sd">/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/</span>
<span class="nv">$args</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="c1">// Author Parameters - Show posts associated with certain author.
// http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters
</span> <span class="s1">'author'</span> <span class="o">=></span> <span class="s1">'1,2,3,'</span><span class="p">,</span> <span class="c1">// (int | string) - use author id or comma-separated list of IDs [use minus (-) to exclude authors by ID ex. 'author' => '-1,-2,-3,']
</span> <span class="s1">'author_name'</span> <span class="o">=></span> <span class="s1">'luetkemj'</span><span class="p">,</span> <span class="c1">// (string) - use 'user_nicename' (NOT name)
</span> <span class="s1">'author__in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span> <span class="p">),</span> <span class="c1">// (array) - use author id (available with Version 3.7).
</span> <span class="s1">'author__not_in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span> <span class="p">),</span> <span class="c1">// (array)' - use author id (available with Version 3.7).
</span>
<span class="c1">// Category Parameters - Show posts associated with certain categories.
// http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
</span> <span class="s1">'cat'</span> <span class="o">=></span> <span class="mi">5</span><span class="p">,</span> <span class="c1">// (int) - Display posts that have this category (and any children of that category), using category id.
</span> <span class="s1">'cat'</span> <span class="o">=></span> <span class="s1">'-12,-34,-56'</span> <span class="c1">// Display all posts except those from a category by prefixing its id with a '-' (minus) sign.
</span> <span class="s1">'category_name'</span> <span class="o">=></span> <span class="s1">'staff, news'</span><span class="p">,</span> <span class="c1">// (string) - Display posts that have these categories (and any children of that category), using category slug.
</span> <span class="s1">'category_name'</span> <span class="o">=></span> <span class="s1">'staff+news'</span><span class="p">,</span> <span class="c1">// (string) - Display posts that have "all" of these categories, using category slug.
</span> <span class="s1">'category__and'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span> <span class="p">),</span> <span class="c1">// (array) - Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6.
</span> <span class="s1">'category__in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span> <span class="p">),</span> <span class="c1">// (array) - Display posts that have this category (not children of that category), using category id.
</span> <span class="s1">'category__not_in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span> <span class="p">),</span> <span class="c1">// (array) - Display posts that DO NOT HAVE these categories (not children of that category), using category id.
</span>
<span class="c1">// Tag Parameters - Show posts associated with certain tags.
// http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
</span> <span class="s1">'tag'</span> <span class="o">=></span> <span class="s1">'cooking'</span><span class="p">,</span> <span class="c1">// (string) - use tag slug.
</span> <span class="s1">'tag_id'</span> <span class="o">=></span> <span class="mi">5</span><span class="p">,</span> <span class="c1">// (int) - use tag id.
</span> <span class="s1">'tag__and'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="c1">// (array) - use tag ids.
</span> <span class="s1">'tag__in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="c1">// (array) - use tag ids.
</span> <span class="s1">'tag__not_in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="c1">// (array) - use tag ids.
</span> <span class="s1">'tag_slug__and'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="s1">'red'</span><span class="p">,</span> <span class="s1">'blue'</span><span class="p">),</span> <span class="c1">// (array) - use tag slugs.
</span> <span class="s1">'tag_slug__in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="s1">'red'</span><span class="p">,</span> <span class="s1">'blue'</span><span class="p">),</span> <span class="c1">// (array) - use tag slugs.
</span>
<span class="c1">// Taxonomy Parameters - Show posts associated with certain taxonomy.
// http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
// Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays)
// This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy queries.
</span> <span class="s1">'tax_query'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="c1">// (array) - use taxonomy parameters (available with Version 3.1).
</span> <span class="s1">'relation'</span> <span class="o">=></span> <span class="s1">'AND'</span><span class="p">,</span> <span class="c1">// (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. Default value is 'AND'.
</span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'taxonomy'</span> <span class="o">=></span> <span class="s1">'color'</span><span class="p">,</span> <span class="c1">// (string) - Taxonomy.
</span> <span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'slug'</span><span class="p">,</span> <span class="c1">// (string) - Select taxonomy term by Possible values are 'term_id', 'name', 'slug' or 'term_taxonomy_id'. Default value is 'term_id'.
</span> <span class="s1">'terms'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="s1">'red'</span><span class="p">,</span> <span class="s1">'blue'</span> <span class="p">),</span> <span class="c1">// (int/string/array) - Taxonomy term(s).
</span> <span class="s1">'include_children'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) - Whether or not to include children for hierarchical taxonomies. Defaults to true.
</span> <span class="s1">'operator'</span> <span class="o">=></span> <span class="s1">'IN'</span> <span class="c1">// (string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND', 'EXISTS' and 'NOT EXISTS'. Default value is 'IN'.
</span> <span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'taxonomy'</span> <span class="o">=></span> <span class="s1">'actor'</span><span class="p">,</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'id'</span><span class="p">,</span>
<span class="s1">'terms'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">103</span><span class="p">,</span> <span class="mi">115</span><span class="p">,</span> <span class="mi">206</span> <span class="p">),</span>
<span class="s1">'include_children'</span> <span class="o">=></span> <span class="kc">false</span><span class="p">,</span>
<span class="s1">'operator'</span> <span class="o">=></span> <span class="s1">'NOT IN'</span>
<span class="p">)</span>
<span class="p">),</span>
<span class="c1">// Post & Page Parameters - Display content based on post and page parameters.
// http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
</span> <span class="s1">'p'</span> <span class="o">=></span> <span class="mi">1</span><span class="p">,</span> <span class="c1">// (int) - use post id.
</span> <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'hello-world'</span><span class="p">,</span> <span class="c1">// (string) - use post slug.
</span> <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'Hello World'</span> <span class="c1">// (string) - use post title (available with Version 4.4)
</span> <span class="s1">'page_id'</span> <span class="o">=></span> <span class="mi">1</span><span class="p">,</span> <span class="c1">// (int) - use page id.
</span> <span class="s1">'pagename'</span> <span class="o">=></span> <span class="s1">'sample-page'</span><span class="p">,</span> <span class="c1">// (string) - use page slug.
</span> <span class="s1">'pagename'</span> <span class="o">=></span> <span class="s1">'contact_us/canada'</span><span class="p">,</span> <span class="c1">// (string) - Display child page using the slug of the parent and the child page, separated ba slash
</span> <span class="s1">'post_name__in'</span> <span class="o">=></span> <span class="s1">'sample-post'</span> <span class="p">(</span><span class="k">array</span><span class="p">)</span> <span class="c1">// - use post slugs. Specify posts to retrieve. (available since Version 4.4)
</span> <span class="s1">'post_parent'</span> <span class="o">=></span> <span class="mi">1</span><span class="p">,</span> <span class="c1">// (int) - use page id. Return just the child Pages. (Only works with heirachical post types.)
</span> <span class="s1">'post_parent__in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span> <span class="c1">// (array) - use post ids. Specify posts whose parent is in an array. NOTE: Introduced in 3.6
</span> <span class="s1">'post_parent__not_in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="c1">// (array) - use post ids. Specify posts whose parent is not in an array.
</span> <span class="s1">'post__in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="c1">// (array) - use post ids. Specify posts to retrieve. ATTENTION If you use sticky posts, they will be included (prepended!) in the posts you retrieve whether you want it or not. To suppress this behaviour use ignore_sticky_posts
</span> <span class="s1">'post__not_in'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="c1">// (array) - use post ids. Specify post NOT to retrieve.
</span> <span class="c1">// NOTE: you cannot combine 'post__in' and 'post__not_in' in the same query
</span>
<span class="c1">// Password Parameters - Show content based on post and page parameters. Remember that default post_type is only set to display posts but not pages.
// http://codex.wordpress.org/Class_Reference/WP_Query#Password_Parameters
</span> <span class="s1">'has_password'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) - available with Version 3.9
</span> <span class="c1">// true for posts with passwords;
</span> <span class="c1">// false for posts without passwords;
</span> <span class="c1">// null for all posts with and without passwords
</span> <span class="s1">'post_password'</span> <span class="o">=></span> <span class="s1">'multi-pass'</span><span class="p">,</span> <span class="c1">// (string) - show posts with a particular password (available with Version 3.9)
</span>
<span class="c1">// Post Type Parameters - Show posts associated with certain type or status.
// http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
</span> <span class="s1">'post_type'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="c1">// (string / array) - use post types. Retrieves posts by Post Types, default value is 'post';
</span> <span class="s1">'post'</span><span class="p">,</span> <span class="c1">// - a post.
</span> <span class="s1">'page'</span><span class="p">,</span> <span class="c1">// - a page.
</span> <span class="s1">'revision'</span><span class="p">,</span> <span class="c1">// - a revision.
</span> <span class="s1">'attachment'</span><span class="p">,</span> <span class="c1">// - an attachment. The default WP_Query sets 'post_status'=>'published', but atchments default to 'post_status'=>'inherit' so you'll need to set the status to 'inherit' or 'any'.
</span> <span class="s1">'nav_menu_item'</span> <span class="c1">// - a navigation menu item
</span> <span class="s1">'my-custom-post-type'</span><span class="p">,</span> <span class="c1">// - Custom Post Types (e.g. movies)
</span> <span class="p">),</span>
<span class="c1">// NOTE: The 'any' keyword available to both post_type and post_status queries cannot be used within an array.
</span> <span class="s1">'post_type'</span> <span class="o">=></span> <span class="s1">'any'</span><span class="p">,</span> <span class="c1">// - retrieves any type except revisions and types with 'exclude_from_search' set to true.
</span>
<span class="c1">// Post Status Parameters - Show posts associated with certain type or status.
// http://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters
</span> <span class="s1">'post_status'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="c1">// (string | array) - use post status. Retrieves posts by Post Status, default value i'publish'.
</span> <span class="s1">'publish'</span><span class="p">,</span> <span class="c1">// - a published post or page.
</span> <span class="s1">'pending'</span><span class="p">,</span> <span class="c1">// - post is pending review.
</span> <span class="s1">'draft'</span><span class="p">,</span> <span class="c1">// - a post in draft status.
</span> <span class="s1">'auto-draft'</span><span class="p">,</span> <span class="c1">// - a newly created post, with no content.
</span> <span class="s1">'future'</span><span class="p">,</span> <span class="c1">// - a post to publish in the future.
</span> <span class="s1">'private'</span><span class="p">,</span> <span class="c1">// - not visible to users who are not logged in.
</span> <span class="s1">'inherit'</span><span class="p">,</span> <span class="c1">// - a revision. see get_children.
</span> <span class="s1">'trash'</span><span class="p">,</span> <span class="c1">// - post is in trashbin (available with Version 2.9).
</span> <span class="p">),</span>
<span class="c1">// NOTE: The 'any' keyword available to both post_type and post_status queries cannot be used within an array.
</span> <span class="s1">'post_status'</span> <span class="o">=></span> <span class="s1">'any'</span><span class="p">,</span> <span class="c1">// - retrieves any status except those from post types with 'exclude_from_search' set to true.
</span>
<span class="c1">// Comment Paremters - @since Version 4.9 Introduced the `$comment_count` parameter.
// https://codex.wordpress.org/Class_Reference/WP_Query#Comment_Parameters
</span> <span class="s1">'comment_count'</span> <span class="o">=></span> <span class="mi">10</span> <span class="c1">// (int | array) The amount of comments your CPT has to have ( Search operator will do a '=' operation )
</span> <span class="s1">'comment_count'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'value'</span> <span class="o">=></span> <span class="mi">10</span> <span class="c1">// (int) - The amount of comments your CPT has to have when comparing
</span> <span class="s1">'compare'</span> <span class="o">=></span> <span class="s1">'='</span> <span class="c1">// (string) - The search operator. Possible values are '=', '!=', '>', '>=', '<', '<='. Default value is '='.
</span> <span class="p">)</span>
<span class="c1">// Pagination Parameters
</span> <span class="c1">//http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
</span> <span class="s1">'posts_per_page'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="c1">// (int) - number of post to show per page (available with Version 2.1). Use 'posts_per_page' => -1 to show all posts.
</span> <span class="c1">// Note: if the query is in a feed, wordpress overwrites this parameter with the stored 'posts_per_rss' option. Treimpose the limit, try using the 'post_limits' filter, or filter 'pre_option_posts_per_rss' and return -1
</span> <span class="s1">'nopaging'</span> <span class="o">=></span> <span class="kc">false</span><span class="p">,</span> <span class="c1">// (bool) - show all posts or use pagination. Default value is 'false', use paging.
</span> <span class="s1">'paged'</span> <span class="o">=></span> <span class="nx">get_query_var</span><span class="p">(</span><span class="s1">'paged'</span><span class="p">),</span> <span class="c1">// (int) - number of page. Show the posts that would normally show up just on page X when usinthe "Older Entries" link.
</span> <span class="c1">// NOTE: Use get_query_var('page'); if you want your query to work in a Page template that you've set as your static front page. The query variable 'page' holds the pagenumber for a single paginated Post or Page that includes the <!--nextpage--> Quicktag in the post content.
</span> <span class="s1">'nopaging'</span> <span class="o">=></span> <span class="kc">false</span><span class="p">,</span> <span class="c1">// (boolean) - show all posts or use pagination. Default value is 'false', use paging.
</span> <span class="s1">'posts_per_archive_page'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="c1">// (int) - number of posts to show per page - on archive pages only. Over-rides posts_per_page and showposts on pages where is_archive() or is_search() would be true.
</span> <span class="s1">'offset'</span> <span class="o">=></span> <span class="mi">3</span><span class="p">,</span> <span class="c1">// (int) - number of post to displace or pass over.
</span> <span class="c1">// Warning: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination. for a workaround see: http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination
</span> <span class="c1">// The 'offset' parameter is ignored when 'posts_per_page'=>-1 (show all posts) is used.
</span> <span class="s1">'paged'</span> <span class="o">=></span> <span class="nx">get_query_var</span><span class="p">(</span><span class="s1">'paged'</span><span class="p">),</span> <span class="c1">// (int) - number of page. Show the posts that would normally show up just on page X when usinthe "Older Entries" link.
</span> <span class="c1">// NOTE: This whole paging thing gets tricky. Some links to help you out:
</span> <span class="c1">// http://codex.wordpress.org/Function_Reference/next_posts_link#Usage_when_querying_the_loop_with_WP_Query
</span> <span class="c1">// http://codex.wordpress.org/Pagination#Troubleshooting_Broken_Pagination
</span> <span class="s1">'page'</span> <span class="o">=></span> <span class="nx">get_query_var</span><span class="p">(</span><span class="s1">'page'</span><span class="p">),</span> <span class="c1">// (int) - number of page for a static front page. Show the posts that would normally show up just on page X of a Static Front Page.
</span> <span class="c1">// NOTE: The query variable 'page' holds the pagenumber for a single paginated Post or Page that includes the <!--nextpage--> Quicktag in the post content.
</span> <span class="s1">'ignore_sticky_posts'</span> <span class="o">=></span> <span class="kc">false</span><span class="p">,</span> <span class="c1">// (boolean) - ignore sticky posts or not (available with Version 3.1, replaced caller_get_posts parameter). Default value is 0 - don't ignore sticky posts. Note: ignore/exclude sticky posts being included at the beginning of posts returned, but the sticky post will still be returned in the natural order of that list of posts returned.
</span>
<span class="c1">// Order & Orderby Parameters - Sort retrieved posts.
// http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
</span> <span class="s1">'order'</span> <span class="o">=></span> <span class="s1">'DESC'</span><span class="p">,</span> <span class="c1">// (string) - Designates the ascending or descending order of the 'orderby' parameter. Default to 'DESC'.
</span> <span class="c1">//Possible Values:
</span> <span class="c1">//'ASC' - ascending order from lowest to highest values (1, 2, 3; a, b, c).
</span> <span class="c1">//'DESC' - descending order from highest to lowest values (3, 2, 1; c, b, a).
</span> <span class="s1">'orderby'</span> <span class="o">=></span> <span class="s1">'date'</span><span class="p">,</span> <span class="c1">// (string) - Sort retrieved posts by parameter. Defaults to 'date'. One or more options can be passed. EX: 'orderby' => 'menu_order title'
</span> <span class="c1">//Possible Values:
</span> <span class="c1">// 'none' - No order (available since Version 2.8).
</span> <span class="c1">// 'ID' - Order by post id. Note the capitalization.
</span> <span class="c1">// 'author' - Order by author. ('post_author' is also accepted.)
</span> <span class="c1">// 'title' - Order by title. ('post_title' is also accepted.)
</span> <span class="c1">// 'name' - Order by post name (post slug). ('post_name' is also accepted.)
</span> <span class="c1">// 'type' - Order by post type (available since Version 4.0). ('post_type' is also accepted.)
</span> <span class="c1">// 'date' - Order by date. ('post_date' is also accepted.)
</span> <span class="c1">// 'modified' - Order by last modified date. ('post_modified' is also accepted.)
</span> <span class="c1">// 'parent' - Order by post/page parent id. ('post_parent' is also accepted.)
</span> <span class="c1">// 'rand' - Random order. You can also use 'RAND(x)' where 'x' is an integer seed value.
</span> <span class="c1">// 'comment_count' - Order by number of comments (available since Version 2.9).
</span> <span class="c1">// 'relevance' - Order by search terms in the following order: First, whether the entire sentence is matched. Second, if all the search terms are within the titles. Third, if any of the search terms appear in the titles. And, fourth, if the full sentence appears in the contents.
</span> <span class="c1">// 'menu_order' - Order by Page Order. Used most often for Pages (Order field in the Edit Page Attributes box) and for Attachments (the integer fields in the Insert / Upload Media Gallery dialog), but could be used for any post type with distinct 'menu_order' values (they all default to 0).
</span> <span class="c1">// 'meta_value' - Note that a 'meta_key=keyname' must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use 'meta_value_num' instead for numeric values.
</span> <span class="c1">// 'meta_type' if you want to cast the meta value as a specific type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED', same as in '$meta_query'. When using 'meta_type' you can also use 'meta_value_*' accordingly. For example, when using DATETIME as 'meta_type' you can use 'meta_value_datetime' to define order structure.
</span> <span class="c1">// 'meta_value_num' - Order by numeric meta value (available since Version 2.8). Also note that a 'meta_key=keyname' must also be present in the query. This value allows for numerical sorting as noted above in 'meta_value'.
</span> <span class="c1">// 'post__in' - Preserve post ID order given in the 'post__in' array (available since Version 3.5). Note - the value of the order parameter does not change the resulting sort order.
</span> <span class="c1">// 'post_name__in' - Preserve post slug order given in the 'post_name__in' array (available since Version 4.6). Note - the value of the order parameter does not change the resulting sort order.
</span> <span class="c1">// 'post_parent__in' - Preserve post parent order given in the 'post_parent__in' array (available since Version 4.6). Note - the value of the order parameter does not change the resulting sort order.
</span>
<span class="c1">// Date Parameters - Show posts associated with a certain time and date period.
// http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
</span> <span class="s1">'year'</span> <span class="o">=></span> <span class="mi">2014</span><span class="p">,</span> <span class="c1">// (int) - 4 digit year (e.g. 2011).
</span> <span class="s1">'monthnum'</span> <span class="o">=></span> <span class="mi">4</span><span class="p">,</span> <span class="c1">// (int) - Month number (from 1 to 12).
</span> <span class="s1">'w'</span> <span class="o">=></span> <span class="mi">25</span><span class="p">,</span> <span class="c1">// (int) - Week of the year (from 0 to 53). Uses the MySQL WEEK command. The mode is dependenon the "start_of_week" option.
</span> <span class="s1">'day'</span> <span class="o">=></span> <span class="mi">17</span><span class="p">,</span> <span class="c1">// (int) - Day of the month (from 1 to 31).
</span> <span class="s1">'hour'</span> <span class="o">=></span> <span class="mi">13</span><span class="p">,</span> <span class="c1">// (int) - Hour (from 0 to 23).
</span> <span class="s1">'minute'</span> <span class="o">=></span> <span class="mi">19</span><span class="p">,</span> <span class="c1">// (int) - Minute (from 0 to 60).
</span> <span class="s1">'second'</span> <span class="o">=></span> <span class="mi">30</span><span class="p">,</span> <span class="c1">// (int) - Second (0 to 60).
</span> <span class="s1">'m'</span> <span class="o">=></span> <span class="mi">201404</span><span class="p">,</span> <span class="c1">// (int) - YearMonth (For e.g.: 201307).
</span> <span class="s1">'date_query'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="c1">// (array) - Date parameters (available with Version 3.7).
</span> <span class="c1">// these are super powerful. check out the codex for more comprehensive code examples http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
</span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'year'</span> <span class="o">=></span> <span class="mi">2014</span><span class="p">,</span> <span class="c1">// (int) - 4 digit year (e.g. 2011).
</span> <span class="s1">'month'</span> <span class="o">=></span> <span class="mi">4</span><span class="p">,</span> <span class="c1">// (int) - Month number (from 1 to 12).
</span> <span class="s1">'week'</span> <span class="o">=></span> <span class="mi">31</span><span class="p">,</span> <span class="c1">// (int) - Week of the year (from 0 to 53).
</span> <span class="s1">'day'</span> <span class="o">=></span> <span class="mi">5</span><span class="p">,</span> <span class="c1">// (int) - Day of the month (from 1 to 31).
</span> <span class="s1">'hour'</span> <span class="o">=></span> <span class="mi">2</span><span class="p">,</span> <span class="c1">// (int) - Hour (from 0 to 23).
</span> <span class="s1">'minute'</span> <span class="o">=></span> <span class="mi">3</span><span class="p">,</span> <span class="c1">// (int) - Minute (from 0 to 59).
</span> <span class="s1">'second'</span> <span class="o">=></span> <span class="mi">36</span><span class="p">,</span> <span class="c1">// (int) - Second (0 to 59).
</span> <span class="s1">'after'</span> <span class="o">=></span> <span class="s1">'January 1st, 2013'</span><span class="p">,</span> <span class="c1">// (string/array) - Date to retrieve posts after. Accepts strtotime()-compatible string, or array of 'year', 'month', 'day'
</span> <span class="s1">'before'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="c1">// (string/array) - Date to retrieve posts after. Accepts strtotime()-compatible string, or array of 'year', 'month', 'day'
</span> <span class="s1">'year'</span> <span class="o">=></span> <span class="mi">2013</span><span class="p">,</span> <span class="c1">// (string) Accepts any four-digit year. Default is empty.
</span> <span class="s1">'month'</span> <span class="o">=></span> <span class="mi">2</span><span class="p">,</span> <span class="c1">// (string) The month of the year. Accepts numbers 1-12. Default: 12.
</span> <span class="s1">'day'</span> <span class="o">=></span> <span class="mi">28</span><span class="p">,</span> <span class="c1">// (string) The day of the month. Accepts numbers 1-31. Default: last day of month.
</span> <span class="p">),</span>
<span class="s1">'inclusive'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (boolean) - For after/before, whether exact value should be matched or not'.
</span> <span class="s1">'compare'</span> <span class="o">=></span> <span class="s1">'='</span><span class="p">,</span> <span class="c1">// (string) - Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' (only in WP >= 3.5), and 'NOT EXISTS' (also only in WP >= 3.5). Default value is '='
</span> <span class="s1">'column'</span> <span class="o">=></span> <span class="s1">'post_date'</span><span class="p">,</span> <span class="c1">// (string) - Column to query against. Default: 'post_date'.
</span> <span class="s1">'relation'</span> <span class="o">=></span> <span class="s1">'AND'</span><span class="p">,</span> <span class="c1">// (string) - OR or AND, how the sub-arrays should be compared. Default: AND.
</span> <span class="p">),</span>
<span class="p">),</span>
<span class="c1">// Custom Field Parameters - Show posts associated with a certain custom field.
// http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
</span> <span class="s1">'meta_key'</span> <span class="o">=></span> <span class="s1">'key'</span><span class="p">,</span> <span class="c1">// (string) - Custom field key.
</span> <span class="s1">'meta_value'</span> <span class="o">=></span> <span class="s1">'value'</span><span class="p">,</span> <span class="c1">// (string) - Custom field value.
</span> <span class="s1">'meta_value_num'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="c1">// (number) - Custom field value.
</span> <span class="s1">'meta_compare'</span> <span class="o">=></span> <span class="s1">'='</span><span class="p">,</span> <span class="c1">// (string) - Operator to test the 'meta_value'. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP' or 'RLIKE'. Default value is '='.
</span> <span class="s1">'meta_query'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="c1">// (array) - Custom field parameters (available with Version 3.1).
</span> <span class="s1">'relation'</span> <span class="o">=></span> <span class="s1">'AND'</span><span class="p">,</span> <span class="c1">// (string) - Possible values are 'AND', 'OR'. The logical relationship between each inner meta_query array when there is more than one. Do not use with a single inner meta_query array.
</span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'key'</span> <span class="o">=></span> <span class="s1">'color'</span><span class="p">,</span> <span class="c1">// (string) - Custom field key.
</span> <span class="s1">'value'</span> <span class="o">=></span> <span class="s1">'blue'</span><span class="p">,</span> <span class="c1">// (string/array) - Custom field value (Note: Array support is limited to a compare value of 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN') Using WP < 3.9? Check out this page for details: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
</span> <span class="s1">'type'</span> <span class="o">=></span> <span class="s1">'CHAR'</span><span class="p">,</span> <span class="c1">// (string) - Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'. The 'type' DATE works with the 'compare' value BETWEEN only if the date is stored at the format YYYYMMDD and tested with this format.
</span> <span class="c1">//NOTE: The 'type' DATE works with the 'compare' value BETWEEN only if the date is stored at the format YYYYMMDD and tested with this format.
</span> <span class="s1">'compare'</span> <span class="o">=></span> <span class="s1">'='</span><span class="p">,</span> <span class="c1">// (string) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' (only in WP >= 3.5), and 'NOT EXISTS' (also only in WP >= 3.5). Default value is '='.
</span> <span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'key'</span> <span class="o">=></span> <span class="s1">'price'</span><span class="p">,</span>
<span class="s1">'value'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span> <span class="mi">1</span><span class="p">,</span><span class="mi">200</span> <span class="p">),</span>
<span class="s1">'compare'</span> <span class="o">=></span> <span class="s1">'NOT LIKE'</span><span class="p">,</span>
<span class="p">)</span>
<span class="p">),</span>
<span class="c1">// Permission Parameters - Display published posts, as well as private posts, if the user has the appropriate capability:
// http://codex.wordpress.org/Class_Reference/WP_Query#Permission_Parameters
</span> <span class="s1">'perm'</span> <span class="o">=></span> <span class="s1">'readable'</span><span class="p">,</span> <span class="c1">// (string) Possible values are 'readable', 'editable'
</span>
<span class="c1">// Mime Type Parameters - Used with the attachments post type.
// https://codex.wordpress.org/Class_Reference/WP_Query#Mime_Type_Parameters
</span> <span class="s1">'post_mime_type'</span> <span class="o">=></span> <span class="s1">'image/gif'</span><span class="p">,</span> <span class="c1">// (string/array) - Allowed mime types.
</span>
<span class="c1">// Caching Parameters
// http://codex.wordpress.org/Class_Reference/WP_Query#Caching_Parameters
// NOTE Caching is a good thing. Setting these to false is generally not advised.
</span> <span class="s1">'cache_results'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) Default is true - Post information cache.
</span> <span class="s1">'update_post_term_cache'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) Default is true - Post meta information cache.
</span> <span class="s1">'update_post_meta_cache'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) Default is true - Post term information cache.
</span> <span class="s1">'no_found_rows'</span> <span class="o">=></span> <span class="kc">false</span><span class="p">,</span> <span class="c1">// (bool) Default is false. WordPress uses SQL_CALC_FOUND_ROWS in most queries in order to implement pagination. Even when you don’t need pagination at all. By Setting this parameter to true you are telling wordPress not to count the total rows and reducing load on the DB. Pagination will NOT WORK when this parameter is set to true. For more information see: http://flavio.tordini.org/speed-up-wordpress-get_posts-and-query_posts-functions
</span>
<span class="c1">// Search Parameter
// http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter
</span> <span class="s1">'s'</span> <span class="o">=></span> <span class="nv">$s</span><span class="p">,</span> <span class="c1">// (string) - Passes along the query string variable from a search. For example usage see: http://www.wprecipes.com/how-to-display-the-number-of-results-in-wordpress-search
</span> <span class="s1">'exact'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) - flag to make it only match whole titles/posts - Default value is false. For more information see: https://gist.github.com/2023628#gistcomment-285118
</span> <span class="s1">'sentence'</span> <span class="o">=></span> <span class="kc">true</span><span class="p">,</span> <span class="c1">// (bool) - flag to make it do a phrase search - Default value is false. For more information see: https://gist.github.com/2023628#gistcomment-285118
</span>
<span class="c1">// Post Field Parameters
// For more info see: http://codex.wordpress.org/Class_Reference/WP_Query#Return_Fields_Parameter
// also https://gist.github.com/luetkemj/2023628/#comment-1003542
</span> <span class="s1">'fields'</span> <span class="o">=></span> <span class="s1">'ids'</span><span class="p">,</span> <span class="c1">// (string) - Which fields to return. All fields are returned by default.
</span> <span class="c1">// Possible values:
</span> <span class="c1">// 'ids' - Return an array of post IDs.
</span> <span class="c1">// 'id=>parent' - Return an associative array [ parent => ID, … ].
</span> <span class="c1">// Passing anything else will return all fields (default) - an array of post objects.
</span>
<span class="c1">// Filters
// For more information on available Filters see: http://codex.wordpress.org/Class_Reference/WP_Query#Filters
</span>
<span class="p">);</span>
<span class="nv">$the_query</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WP_Query</span><span class="p">(</span> <span class="nv">$args</span> <span class="p">);</span>
<span class="c1">// The Loop
</span><span class="k">if</span> <span class="p">(</span> <span class="nv">$the_query</span><span class="o">-></span><span class="na">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span>
<span class="k">while</span> <span class="p">(</span> <span class="nv">$the_query</span><span class="o">-></span><span class="na">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="nv">$the_query</span><span class="o">-></span><span class="na">the_post</span><span class="p">();</span>
<span class="c1">// Do Stuff
</span><span class="k">endwhile</span><span class="p">;</span>
<span class="k">endif</span><span class="p">;</span>
<span class="c1">// Reset Post Data
</span><span class="nx">wp_reset_postdata</span><span class="p">();</span>
<span class="cp">?></span>
</code></pre></div></div>
<h2 id="contributing">Contributing<a class="anchorjs-link " href="#contributing" aria-label="Anchor" data-anchorjs-icon="" style="font: 1em/1 anchorjs-icons; padding-left: 0.375em;"></a></h2>
<p>Contributions are welcome.</p>
<p>Find a problem? Open an <a href="https://github.com/luetkemj/wp-query-ref/issues">issue</a>!</p>
<p>Better yet, fix it yourself and open a pull request!</p>
<p>Never submitted a pull request before? You can learn how from this free series <a href="https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github">How to Contribute to an Open Source Project on GitHub</a></p>
<h3 id="contributors">Contributors<a class="anchorjs-link " href="#contributors" aria-label="Anchor" data-anchorjs-icon="" style="font: 1em/1 anchorjs-icons; padding-left: 0.375em;"></a></h2>
<p class="contributors">
<a href="https://github.com/luetkemj" title="luetkemj"><img src="https://avatars1.githubusercontent.com/u/925980?s=80&v=4" alt="luetkemj"></a>
<a href="https://github.com/streeetlamp" title="streeetlamp"><img src="https://avatars2.githubusercontent.com/u/1740634?s=80&v=4" alt="streeetlamp"></a>
<a href="https://github.com/conorbarclay" title="conorbarclay"><img src="https://avatars3.githubusercontent.com/u/12818737?s=80&v=4" alt="conorbarclay"></a>
</p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.1.0/anchor.min.js" integrity="sha256-lZaRhKri35AyJSypXXs4o6OPFTbTmUoltBbDCbdzegg=" crossorigin="anonymous"></script>
<script>anchors.add();</script>
</body></html>