author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Query API |
|
4 |
* |
|
5 |
* The query API attempts to get which part of WordPress the user is on. It |
|
6 |
* also provides functionality for getting URL query information. |
|
7 |
* |
|
16 | 8 |
* @link https://developer.wordpress.org/themes/basics/the-loop/ More information on The Loop. |
0 | 9 |
* |
10 |
* @package WordPress |
|
11 |
* @subpackage Query |
|
12 |
*/ |
|
13 |
||
14 |
/** |
|
18 | 15 |
* Retrieves the value of a query variable in the WP_Query class. |
0 | 16 |
* |
17 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
18 |
* @since 3.9.0 The `$default_value` argument was introduced. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* |
16 | 20 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 21 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
22 |
* @param string $query_var The variable key to retrieve. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
23 |
* @param mixed $default_value Optional. Value to return if the query variable is not set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
24 |
* Default empty string. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @return mixed Contents of the query variable. |
0 | 26 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
27 |
function get_query_var( $query_var, $default_value = '' ) { |
0 | 28 |
global $wp_query; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
29 |
return $wp_query->get( $query_var, $default_value ); |
0 | 30 |
} |
31 |
||
32 |
/** |
|
18 | 33 |
* Retrieves the currently queried object. |
0 | 34 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* Wrapper for WP_Query::get_queried_object(). |
0 | 36 |
* |
37 |
* @since 3.1.0 |
|
38 |
* |
|
16 | 39 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* |
18 | 41 |
* @return WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object. |
0 | 42 |
*/ |
43 |
function get_queried_object() { |
|
44 |
global $wp_query; |
|
45 |
return $wp_query->get_queried_object(); |
|
46 |
} |
|
47 |
||
48 |
/** |
|
18 | 49 |
* Retrieves the ID of the currently queried object. |
0 | 50 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
* Wrapper for WP_Query::get_queried_object_id(). |
0 | 52 |
* |
53 |
* @since 3.1.0 |
|
54 |
* |
|
16 | 55 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* @return int ID of the queried object. |
0 | 58 |
*/ |
59 |
function get_queried_object_id() { |
|
60 |
global $wp_query; |
|
61 |
return $wp_query->get_queried_object_id(); |
|
62 |
} |
|
63 |
||
64 |
/** |
|
18 | 65 |
* Sets the value of a query variable in the WP_Query class. |
0 | 66 |
* |
67 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* |
16 | 69 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 70 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
71 |
* @param string $query_var Query variable key. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
72 |
* @param mixed $value Query variable value. |
0 | 73 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
74 |
function set_query_var( $query_var, $value ) { |
0 | 75 |
global $wp_query; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
76 |
$wp_query->set( $query_var, $value ); |
0 | 77 |
} |
78 |
||
79 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* Sets up The Loop with query parameters. |
0 | 81 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* Note: This function will completely override the main query and isn't intended for use |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* by plugins or themes. Its overly-simplistic approach to modifying the main query can be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* problematic and should be avoided wherever possible. In most cases, there are better, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* more performant options for modifying the main query such as via the {@see 'pre_get_posts'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* action within WP_Query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* This must not be used within the WordPress Loop. |
0 | 89 |
* |
90 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* |
16 | 92 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 93 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
* @param array|string $query Array or string of WP_Query arguments. |
16 | 95 |
* @return WP_Post[]|int[] Array of post objects or post IDs. |
0 | 96 |
*/ |
9 | 97 |
function query_posts( $query ) { |
0 | 98 |
$GLOBALS['wp_query'] = new WP_Query(); |
9 | 99 |
return $GLOBALS['wp_query']->query( $query ); |
0 | 100 |
} |
101 |
||
102 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* Destroys the previous query and sets up a new query. |
0 | 104 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
* This should be used after query_posts() and before another query_posts(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
* This will remove obscure bugs that occur when the previous WP_Query object |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* is not destroyed properly before another is set up. |
0 | 108 |
* |
109 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* |
16 | 111 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
* @global WP_Query $wp_the_query Copy of the global WP_Query instance created during wp_reset_query(). |
0 | 113 |
*/ |
114 |
function wp_reset_query() { |
|
115 |
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; |
|
116 |
wp_reset_postdata(); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* After looping through a separate query, this function restores |
|
121 |
* the $post global to the current post in the main query. |
|
122 |
* |
|
123 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* |
16 | 125 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 126 |
*/ |
127 |
function wp_reset_postdata() { |
|
128 |
global $wp_query; |
|
5 | 129 |
|
130 |
if ( isset( $wp_query ) ) { |
|
131 |
$wp_query->reset_postdata(); |
|
132 |
} |
|
0 | 133 |
} |
134 |
||
135 |
/* |
|
136 |
* Query type checks. |
|
137 |
*/ |
|
138 |
||
139 |
/** |
|
9 | 140 |
* Determines whether the query is for an existing archive page. |
0 | 141 |
* |
18 | 142 |
* Archive pages include category, tag, author, date, custom post type, |
143 |
* and custom taxonomy based archives. |
|
0 | 144 |
* |
9 | 145 |
* For more information on this and similar theme functions, check out |
146 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
147 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
148 |
* |
|
0 | 149 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
* |
18 | 151 |
* @see is_category() |
152 |
* @see is_tag() |
|
153 |
* @see is_author() |
|
154 |
* @see is_date() |
|
155 |
* @see is_post_type_archive() |
|
156 |
* @see is_tax() |
|
16 | 157 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 158 |
* |
16 | 159 |
* @return bool Whether the query is for an existing archive page. |
0 | 160 |
*/ |
161 |
function is_archive() { |
|
162 |
global $wp_query; |
|
163 |
||
164 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 166 |
return false; |
167 |
} |
|
168 |
||
169 |
return $wp_query->is_archive(); |
|
170 |
} |
|
171 |
||
172 |
/** |
|
9 | 173 |
* Determines whether the query is for an existing post type archive page. |
174 |
* |
|
175 |
* For more information on this and similar theme functions, check out |
|
176 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
177 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 178 |
* |
179 |
* @since 3.1.0 |
|
180 |
* |
|
16 | 181 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
* |
16 | 183 |
* @param string|string[] $post_types Optional. Post type or array of posts types |
184 |
* to check against. Default empty. |
|
185 |
* @return bool Whether the query is for an existing post type archive page. |
|
0 | 186 |
*/ |
187 |
function is_post_type_archive( $post_types = '' ) { |
|
188 |
global $wp_query; |
|
189 |
||
190 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 192 |
return false; |
193 |
} |
|
194 |
||
195 |
return $wp_query->is_post_type_archive( $post_types ); |
|
196 |
} |
|
197 |
||
198 |
/** |
|
9 | 199 |
* Determines whether the query is for an existing attachment page. |
200 |
* |
|
201 |
* For more information on this and similar theme functions, check out |
|
202 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
203 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 204 |
* |
205 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* |
16 | 207 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 208 |
* |
16 | 209 |
* @param int|string|int[]|string[] $attachment Optional. Attachment ID, title, slug, or array of such |
210 |
* to check against. Default empty. |
|
211 |
* @return bool Whether the query is for an existing attachment page. |
|
0 | 212 |
*/ |
5 | 213 |
function is_attachment( $attachment = '' ) { |
0 | 214 |
global $wp_query; |
215 |
||
216 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 218 |
return false; |
219 |
} |
|
220 |
||
5 | 221 |
return $wp_query->is_attachment( $attachment ); |
0 | 222 |
} |
223 |
||
224 |
/** |
|
9 | 225 |
* Determines whether the query is for an existing author archive page. |
0 | 226 |
* |
227 |
* If the $author parameter is specified, this function will additionally |
|
228 |
* check if the query is for one of the authors specified. |
|
229 |
* |
|
9 | 230 |
* For more information on this and similar theme functions, check out |
231 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
232 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
233 |
* |
|
0 | 234 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* |
16 | 236 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 237 |
* |
16 | 238 |
* @param int|string|int[]|string[] $author Optional. User ID, nickname, nicename, or array of such |
239 |
* to check against. Default empty. |
|
240 |
* @return bool Whether the query is for an existing author archive page. |
|
0 | 241 |
*/ |
242 |
function is_author( $author = '' ) { |
|
243 |
global $wp_query; |
|
244 |
||
245 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 247 |
return false; |
248 |
} |
|
249 |
||
250 |
return $wp_query->is_author( $author ); |
|
251 |
} |
|
252 |
||
253 |
/** |
|
9 | 254 |
* Determines whether the query is for an existing category archive page. |
0 | 255 |
* |
256 |
* If the $category parameter is specified, this function will additionally |
|
257 |
* check if the query is for one of the categories specified. |
|
258 |
* |
|
9 | 259 |
* For more information on this and similar theme functions, check out |
260 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
261 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
262 |
* |
|
0 | 263 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* |
16 | 265 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 266 |
* |
16 | 267 |
* @param int|string|int[]|string[] $category Optional. Category ID, name, slug, or array of such |
268 |
* to check against. Default empty. |
|
269 |
* @return bool Whether the query is for an existing category archive page. |
|
0 | 270 |
*/ |
271 |
function is_category( $category = '' ) { |
|
272 |
global $wp_query; |
|
273 |
||
274 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 276 |
return false; |
277 |
} |
|
278 |
||
279 |
return $wp_query->is_category( $category ); |
|
280 |
} |
|
281 |
||
282 |
/** |
|
9 | 283 |
* Determines whether the query is for an existing tag archive page. |
0 | 284 |
* |
285 |
* If the $tag parameter is specified, this function will additionally |
|
286 |
* check if the query is for one of the tags specified. |
|
287 |
* |
|
9 | 288 |
* For more information on this and similar theme functions, check out |
289 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
290 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
291 |
* |
|
0 | 292 |
* @since 2.3.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
* |
16 | 294 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 295 |
* |
16 | 296 |
* @param int|string|int[]|string[] $tag Optional. Tag ID, name, slug, or array of such |
297 |
* to check against. Default empty. |
|
298 |
* @return bool Whether the query is for an existing tag archive page. |
|
0 | 299 |
*/ |
300 |
function is_tag( $tag = '' ) { |
|
301 |
global $wp_query; |
|
302 |
||
303 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 305 |
return false; |
306 |
} |
|
307 |
||
308 |
return $wp_query->is_tag( $tag ); |
|
309 |
} |
|
310 |
||
311 |
/** |
|
9 | 312 |
* Determines whether the query is for an existing custom taxonomy archive page. |
0 | 313 |
* |
314 |
* If the $taxonomy parameter is specified, this function will additionally |
|
315 |
* check if the query is for that specific $taxonomy. |
|
316 |
* |
|
317 |
* If the $term parameter is specified in addition to the $taxonomy parameter, |
|
318 |
* this function will additionally check if the query is for one of the terms |
|
319 |
* specified. |
|
320 |
* |
|
9 | 321 |
* For more information on this and similar theme functions, check out |
322 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
323 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
324 |
* |
|
0 | 325 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* |
16 | 327 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 328 |
* |
16 | 329 |
* @param string|string[] $taxonomy Optional. Taxonomy slug or slugs to check against. |
330 |
* Default empty. |
|
331 |
* @param int|string|int[]|string[] $term Optional. Term ID, name, slug, or array of such |
|
332 |
* to check against. Default empty. |
|
333 |
* @return bool Whether the query is for an existing custom taxonomy archive page. |
|
334 |
* True for custom taxonomy archive pages, false for built-in taxonomies |
|
335 |
* (category and tag archives). |
|
0 | 336 |
*/ |
337 |
function is_tax( $taxonomy = '', $term = '' ) { |
|
338 |
global $wp_query; |
|
339 |
||
340 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 342 |
return false; |
343 |
} |
|
344 |
||
345 |
return $wp_query->is_tax( $taxonomy, $term ); |
|
346 |
} |
|
347 |
||
348 |
/** |
|
9 | 349 |
* Determines whether the query is for an existing date archive. |
350 |
* |
|
351 |
* For more information on this and similar theme functions, check out |
|
352 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
353 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 354 |
* |
355 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
* |
16 | 357 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 358 |
* |
16 | 359 |
* @return bool Whether the query is for an existing date archive. |
0 | 360 |
*/ |
361 |
function is_date() { |
|
362 |
global $wp_query; |
|
363 |
||
364 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 366 |
return false; |
367 |
} |
|
368 |
||
369 |
return $wp_query->is_date(); |
|
370 |
} |
|
371 |
||
372 |
/** |
|
9 | 373 |
* Determines whether the query is for an existing day archive. |
374 |
* |
|
375 |
* A conditional check to test whether the page is a date-based archive page displaying posts for the current day. |
|
376 |
* |
|
377 |
* For more information on this and similar theme functions, check out |
|
378 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
379 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 380 |
* |
381 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* |
16 | 383 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 384 |
* |
16 | 385 |
* @return bool Whether the query is for an existing day archive. |
0 | 386 |
*/ |
387 |
function is_day() { |
|
388 |
global $wp_query; |
|
389 |
||
390 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 392 |
return false; |
393 |
} |
|
394 |
||
395 |
return $wp_query->is_day(); |
|
396 |
} |
|
397 |
||
398 |
/** |
|
9 | 399 |
* Determines whether the query is for a feed. |
400 |
* |
|
401 |
* For more information on this and similar theme functions, check out |
|
402 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
403 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 404 |
* |
405 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* |
16 | 407 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 408 |
* |
16 | 409 |
* @param string|string[] $feeds Optional. Feed type or array of feed types |
410 |
* to check against. Default empty. |
|
411 |
* @return bool Whether the query is for a feed. |
|
0 | 412 |
*/ |
413 |
function is_feed( $feeds = '' ) { |
|
414 |
global $wp_query; |
|
415 |
||
416 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 418 |
return false; |
419 |
} |
|
420 |
||
421 |
return $wp_query->is_feed( $feeds ); |
|
422 |
} |
|
423 |
||
424 |
/** |
|
425 |
* Is the query for a comments feed? |
|
426 |
* |
|
427 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* |
16 | 429 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 430 |
* |
16 | 431 |
* @return bool Whether the query is for a comments feed. |
0 | 432 |
*/ |
433 |
function is_comment_feed() { |
|
434 |
global $wp_query; |
|
435 |
||
436 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 438 |
return false; |
439 |
} |
|
440 |
||
441 |
return $wp_query->is_comment_feed(); |
|
442 |
} |
|
443 |
||
444 |
/** |
|
9 | 445 |
* Determines whether the query is for the front page of the site. |
0 | 446 |
* |
447 |
* This is for what is displayed at your site's main URL. |
|
448 |
* |
|
449 |
* Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. |
|
450 |
* |
|
451 |
* If you set a static page for the front page of your site, this function will return |
|
452 |
* true when viewing that page. |
|
453 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
454 |
* Otherwise the same as {@see is_home()}. |
0 | 455 |
* |
9 | 456 |
* For more information on this and similar theme functions, check out |
457 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
458 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
459 |
* |
|
0 | 460 |
* @since 2.5.0 |
461 |
* |
|
16 | 462 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* |
16 | 464 |
* @return bool Whether the query is for the front page of the site. |
0 | 465 |
*/ |
466 |
function is_front_page() { |
|
467 |
global $wp_query; |
|
468 |
||
469 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 471 |
return false; |
472 |
} |
|
473 |
||
474 |
return $wp_query->is_front_page(); |
|
475 |
} |
|
476 |
||
477 |
/** |
|
9 | 478 |
* Determines whether the query is for the blog homepage. |
0 | 479 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* The blog homepage is the page that shows the time-based blog content of the site. |
0 | 481 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* is_home() is dependent on the site's "Front page displays" Reading Settings 'show_on_front' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* and 'page_for_posts'. |
0 | 484 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
* If a static page is set for the front page of the site, this function will return true only |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
* on the page you set as the "Posts page". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* |
9 | 488 |
* For more information on this and similar theme functions, check out |
489 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
490 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
491 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @since 1.5.0 |
0 | 493 |
* |
494 |
* @see is_front_page() |
|
16 | 495 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 496 |
* |
16 | 497 |
* @return bool Whether the query is for the blog homepage. |
0 | 498 |
*/ |
499 |
function is_home() { |
|
500 |
global $wp_query; |
|
501 |
||
502 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 504 |
return false; |
505 |
} |
|
506 |
||
507 |
return $wp_query->is_home(); |
|
508 |
} |
|
509 |
||
510 |
/** |
|
9 | 511 |
* Determines whether the query is for the Privacy Policy page. |
512 |
* |
|
513 |
* The Privacy Policy page is the page that shows the Privacy Policy content of the site. |
|
514 |
* |
|
515 |
* is_privacy_policy() is dependent on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'. |
|
516 |
* |
|
517 |
* This function will return true only on the page you set as the "Privacy Policy page". |
|
518 |
* |
|
519 |
* For more information on this and similar theme functions, check out |
|
520 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
521 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
522 |
* |
|
523 |
* @since 5.2.0 |
|
524 |
* |
|
16 | 525 |
* @global WP_Query $wp_query WordPress Query object. |
9 | 526 |
* |
16 | 527 |
* @return bool Whether the query is for the Privacy Policy page. |
9 | 528 |
*/ |
529 |
function is_privacy_policy() { |
|
530 |
global $wp_query; |
|
531 |
||
532 |
if ( ! isset( $wp_query ) ) { |
|
533 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
|
534 |
return false; |
|
535 |
} |
|
536 |
||
537 |
return $wp_query->is_privacy_policy(); |
|
538 |
} |
|
539 |
||
540 |
/** |
|
541 |
* Determines whether the query is for an existing month archive. |
|
542 |
* |
|
543 |
* For more information on this and similar theme functions, check out |
|
544 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
545 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 546 |
* |
547 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
* |
16 | 549 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 550 |
* |
16 | 551 |
* @return bool Whether the query is for an existing month archive. |
0 | 552 |
*/ |
553 |
function is_month() { |
|
554 |
global $wp_query; |
|
555 |
||
556 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 558 |
return false; |
559 |
} |
|
560 |
||
561 |
return $wp_query->is_month(); |
|
562 |
} |
|
563 |
||
564 |
/** |
|
9 | 565 |
* Determines whether the query is for an existing single page. |
0 | 566 |
* |
567 |
* If the $page parameter is specified, this function will additionally |
|
568 |
* check if the query is for one of the pages specified. |
|
569 |
* |
|
9 | 570 |
* For more information on this and similar theme functions, check out |
571 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
572 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
573 |
* |
|
18 | 574 |
* @since 1.5.0 |
575 |
* |
|
0 | 576 |
* @see is_single() |
577 |
* @see is_singular() |
|
16 | 578 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 579 |
* |
16 | 580 |
* @param int|string|int[]|string[] $page Optional. Page ID, title, slug, or array of such |
581 |
* to check against. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
* @return bool Whether the query is for an existing single page. |
0 | 583 |
*/ |
584 |
function is_page( $page = '' ) { |
|
585 |
global $wp_query; |
|
586 |
||
587 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 589 |
return false; |
590 |
} |
|
591 |
||
592 |
return $wp_query->is_page( $page ); |
|
593 |
} |
|
594 |
||
595 |
/** |
|
16 | 596 |
* Determines whether the query is for a paged result and not for the first page. |
9 | 597 |
* |
598 |
* For more information on this and similar theme functions, check out |
|
599 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
600 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 601 |
* |
602 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
* |
16 | 604 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 605 |
* |
16 | 606 |
* @return bool Whether the query is for a paged result. |
0 | 607 |
*/ |
608 |
function is_paged() { |
|
609 |
global $wp_query; |
|
610 |
||
611 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 613 |
return false; |
614 |
} |
|
615 |
||
616 |
return $wp_query->is_paged(); |
|
617 |
} |
|
618 |
||
619 |
/** |
|
9 | 620 |
* Determines whether the query is for a post or page preview. |
621 |
* |
|
622 |
* For more information on this and similar theme functions, check out |
|
623 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
624 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 625 |
* |
626 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* |
16 | 628 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 629 |
* |
16 | 630 |
* @return bool Whether the query is for a post or page preview. |
0 | 631 |
*/ |
632 |
function is_preview() { |
|
633 |
global $wp_query; |
|
634 |
||
635 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 637 |
return false; |
638 |
} |
|
639 |
||
640 |
return $wp_query->is_preview(); |
|
641 |
} |
|
642 |
||
643 |
/** |
|
16 | 644 |
* Is the query for the robots.txt file? |
0 | 645 |
* |
646 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
* |
16 | 648 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 649 |
* |
16 | 650 |
* @return bool Whether the query is for the robots.txt file. |
0 | 651 |
*/ |
652 |
function is_robots() { |
|
653 |
global $wp_query; |
|
654 |
||
655 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 657 |
return false; |
658 |
} |
|
659 |
||
660 |
return $wp_query->is_robots(); |
|
661 |
} |
|
662 |
||
663 |
/** |
|
16 | 664 |
* Is the query for the favicon.ico file? |
665 |
* |
|
666 |
* @since 5.4.0 |
|
667 |
* |
|
668 |
* @global WP_Query $wp_query WordPress Query object. |
|
669 |
* |
|
670 |
* @return bool Whether the query is for the favicon.ico file. |
|
671 |
*/ |
|
672 |
function is_favicon() { |
|
673 |
global $wp_query; |
|
674 |
||
675 |
if ( ! isset( $wp_query ) ) { |
|
676 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
|
677 |
return false; |
|
678 |
} |
|
679 |
||
680 |
return $wp_query->is_favicon(); |
|
681 |
} |
|
682 |
||
683 |
/** |
|
9 | 684 |
* Determines whether the query is for a search. |
685 |
* |
|
686 |
* For more information on this and similar theme functions, check out |
|
687 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
688 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 689 |
* |
690 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* |
16 | 692 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 693 |
* |
16 | 694 |
* @return bool Whether the query is for a search. |
0 | 695 |
*/ |
696 |
function is_search() { |
|
697 |
global $wp_query; |
|
698 |
||
699 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 701 |
return false; |
702 |
} |
|
703 |
||
704 |
return $wp_query->is_search(); |
|
705 |
} |
|
706 |
||
707 |
/** |
|
9 | 708 |
* Determines whether the query is for an existing single post. |
0 | 709 |
* |
710 |
* Works for any post type, except attachments and pages |
|
711 |
* |
|
712 |
* If the $post parameter is specified, this function will additionally |
|
713 |
* check if the query is for one of the Posts specified. |
|
714 |
* |
|
9 | 715 |
* For more information on this and similar theme functions, check out |
716 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
717 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
718 |
* |
|
18 | 719 |
* @since 1.5.0 |
720 |
* |
|
0 | 721 |
* @see is_page() |
722 |
* @see is_singular() |
|
16 | 723 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 724 |
* |
16 | 725 |
* @param int|string|int[]|string[] $post Optional. Post ID, title, slug, or array of such |
726 |
* to check against. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
* @return bool Whether the query is for an existing single post. |
0 | 728 |
*/ |
729 |
function is_single( $post = '' ) { |
|
730 |
global $wp_query; |
|
731 |
||
732 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 734 |
return false; |
735 |
} |
|
736 |
||
737 |
return $wp_query->is_single( $post ); |
|
738 |
} |
|
739 |
||
740 |
/** |
|
9 | 741 |
* Determines whether the query is for an existing single post of any post type |
742 |
* (post, attachment, page, custom post types). |
|
0 | 743 |
* |
744 |
* If the $post_types parameter is specified, this function will additionally |
|
745 |
* check if the query is for one of the Posts Types specified. |
|
746 |
* |
|
9 | 747 |
* For more information on this and similar theme functions, check out |
748 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
749 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
750 |
* |
|
18 | 751 |
* @since 1.5.0 |
752 |
* |
|
0 | 753 |
* @see is_page() |
754 |
* @see is_single() |
|
16 | 755 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 756 |
* |
16 | 757 |
* @param string|string[] $post_types Optional. Post type or array of post types |
758 |
* to check against. Default empty. |
|
759 |
* @return bool Whether the query is for an existing single post |
|
760 |
* or any of the given post types. |
|
0 | 761 |
*/ |
762 |
function is_singular( $post_types = '' ) { |
|
763 |
global $wp_query; |
|
764 |
||
765 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 767 |
return false; |
768 |
} |
|
769 |
||
770 |
return $wp_query->is_singular( $post_types ); |
|
771 |
} |
|
772 |
||
773 |
/** |
|
9 | 774 |
* Determines whether the query is for a specific time. |
775 |
* |
|
776 |
* For more information on this and similar theme functions, check out |
|
777 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
778 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 779 |
* |
780 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* |
16 | 782 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 783 |
* |
16 | 784 |
* @return bool Whether the query is for a specific time. |
0 | 785 |
*/ |
786 |
function is_time() { |
|
787 |
global $wp_query; |
|
788 |
||
789 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 791 |
return false; |
792 |
} |
|
793 |
||
794 |
return $wp_query->is_time(); |
|
795 |
} |
|
796 |
||
797 |
/** |
|
9 | 798 |
* Determines whether the query is for a trackback endpoint call. |
799 |
* |
|
800 |
* For more information on this and similar theme functions, check out |
|
801 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
802 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 803 |
* |
804 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
* |
16 | 806 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 807 |
* |
16 | 808 |
* @return bool Whether the query is for a trackback endpoint call. |
0 | 809 |
*/ |
810 |
function is_trackback() { |
|
811 |
global $wp_query; |
|
812 |
||
813 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 815 |
return false; |
816 |
} |
|
817 |
||
818 |
return $wp_query->is_trackback(); |
|
819 |
} |
|
820 |
||
821 |
/** |
|
9 | 822 |
* Determines whether the query is for an existing year archive. |
823 |
* |
|
824 |
* For more information on this and similar theme functions, check out |
|
825 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
826 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 827 |
* |
828 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* |
16 | 830 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 831 |
* |
16 | 832 |
* @return bool Whether the query is for an existing year archive. |
0 | 833 |
*/ |
834 |
function is_year() { |
|
835 |
global $wp_query; |
|
836 |
||
837 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 839 |
return false; |
840 |
} |
|
841 |
||
842 |
return $wp_query->is_year(); |
|
843 |
} |
|
844 |
||
845 |
/** |
|
9 | 846 |
* Determines whether the query has resulted in a 404 (returns no results). |
847 |
* |
|
848 |
* For more information on this and similar theme functions, check out |
|
849 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
850 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 851 |
* |
852 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
* |
16 | 854 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 855 |
* |
16 | 856 |
* @return bool Whether the query is a 404 error. |
0 | 857 |
*/ |
858 |
function is_404() { |
|
859 |
global $wp_query; |
|
860 |
||
861 |
if ( ! isset( $wp_query ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
0 | 863 |
return false; |
864 |
} |
|
865 |
||
866 |
return $wp_query->is_404(); |
|
867 |
} |
|
868 |
||
869 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
* Is the query for an embedded post? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
* |
16 | 874 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
* |
16 | 876 |
* @return bool Whether the query is for an embedded post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
function is_embed() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
global $wp_query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
if ( ! isset( $wp_query ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
return $wp_query->is_embed(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
/** |
9 | 890 |
* Determines whether the query is the main query. |
891 |
* |
|
892 |
* For more information on this and similar theme functions, check out |
|
893 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
894 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 895 |
* |
896 |
* @since 3.3.0 |
|
897 |
* |
|
16 | 898 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* |
16 | 900 |
* @return bool Whether the query is the main query. |
0 | 901 |
*/ |
902 |
function is_main_query() { |
|
18 | 903 |
global $wp_query; |
904 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
905 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
906 |
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '6.1.0' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
907 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
908 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
909 |
|
0 | 910 |
if ( 'pre_get_posts' === current_filter() ) { |
18 | 911 |
_doing_it_wrong( |
912 |
__FUNCTION__, |
|
913 |
sprintf( |
|
914 |
/* translators: 1: pre_get_posts, 2: WP_Query->is_main_query(), 3: is_main_query(), 4: Documentation URL. */ |
|
915 |
__( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ), |
|
916 |
'<code>pre_get_posts</code>', |
|
917 |
'<code>WP_Query->is_main_query()</code>', |
|
918 |
'<code>is_main_query()</code>', |
|
919 |
__( 'https://developer.wordpress.org/reference/functions/is_main_query/' ) |
|
920 |
), |
|
921 |
'3.7.0' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
); |
0 | 923 |
} |
924 |
||
925 |
return $wp_query->is_main_query(); |
|
926 |
} |
|
927 |
||
928 |
/* |
|
929 |
* The Loop. Post loop control. |
|
930 |
*/ |
|
931 |
||
932 |
/** |
|
16 | 933 |
* Determines whether current WordPress query has posts to loop over. |
0 | 934 |
* |
935 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
* |
16 | 937 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 938 |
* |
16 | 939 |
* @return bool True if posts are available, false if end of the loop. |
0 | 940 |
*/ |
941 |
function have_posts() { |
|
942 |
global $wp_query; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
943 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
944 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
945 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
946 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
947 |
|
0 | 948 |
return $wp_query->have_posts(); |
949 |
} |
|
950 |
||
951 |
/** |
|
9 | 952 |
* Determines whether the caller is in the Loop. |
953 |
* |
|
954 |
* For more information on this and similar theme functions, check out |
|
955 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
956 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 957 |
* |
958 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
* |
16 | 960 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 961 |
* |
962 |
* @return bool True if caller is within loop, false if loop hasn't started or ended. |
|
963 |
*/ |
|
964 |
function in_the_loop() { |
|
965 |
global $wp_query; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
966 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
967 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
968 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
969 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
970 |
|
0 | 971 |
return $wp_query->in_the_loop; |
972 |
} |
|
973 |
||
974 |
/** |
|
975 |
* Rewind the loop posts. |
|
976 |
* |
|
977 |
* @since 1.5.0 |
|
978 |
* |
|
16 | 979 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 980 |
*/ |
981 |
function rewind_posts() { |
|
982 |
global $wp_query; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
983 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
984 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
985 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
986 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
987 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
$wp_query->rewind_posts(); |
0 | 989 |
} |
990 |
||
991 |
/** |
|
992 |
* Iterate the post index in the loop. |
|
993 |
* |
|
994 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* |
16 | 996 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 997 |
*/ |
998 |
function the_post() { |
|
999 |
global $wp_query; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1000 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1001 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1002 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1003 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1004 |
|
0 | 1005 |
$wp_query->the_post(); |
1006 |
} |
|
1007 |
||
1008 |
/* |
|
1009 |
* Comments loop. |
|
1010 |
*/ |
|
1011 |
||
1012 |
/** |
|
16 | 1013 |
* Determines whether current WordPress query has comments to loop over. |
0 | 1014 |
* |
1015 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
* |
16 | 1017 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 1018 |
* |
16 | 1019 |
* @return bool True if comments are available, false if no more comments. |
0 | 1020 |
*/ |
1021 |
function have_comments() { |
|
1022 |
global $wp_query; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1023 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1024 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1025 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1026 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1027 |
|
0 | 1028 |
return $wp_query->have_comments(); |
1029 |
} |
|
1030 |
||
1031 |
/** |
|
1032 |
* Iterate comment index in the comment loop. |
|
1033 |
* |
|
1034 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
* |
16 | 1036 |
* @global WP_Query $wp_query WordPress Query object. |
0 | 1037 |
*/ |
1038 |
function the_comment() { |
|
1039 |
global $wp_query; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1040 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1041 |
if ( ! isset( $wp_query ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1042 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1043 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1044 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1045 |
$wp_query->the_comment(); |
0 | 1046 |
} |
1047 |
||
1048 |
/** |
|
1049 |
* Redirect old slugs to the correct permalink. |
|
1050 |
* |
|
1051 |
* Attempts to find the current slug from the past slugs. |
|
1052 |
* |
|
1053 |
* @since 2.1.0 |
|
1054 |
*/ |
|
1055 |
function wp_old_slug_redirect() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
if ( is_404() && '' !== get_query_var( 'name' ) ) { |
16 | 1057 |
// Guess the current post type based on the query vars. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
if ( get_query_var( 'post_type' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
$post_type = get_query_var( 'post_type' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
} elseif ( get_query_var( 'attachment' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
$post_type = 'attachment'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
} elseif ( get_query_var( 'pagename' ) ) { |
0 | 1063 |
$post_type = 'page'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
} else { |
0 | 1065 |
$post_type = 'post'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
} |
0 | 1067 |
|
1068 |
if ( is_array( $post_type ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
if ( count( $post_type ) > 1 ) { |
0 | 1070 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
} |
5 | 1072 |
$post_type = reset( $post_type ); |
0 | 1073 |
} |
1074 |
||
16 | 1075 |
// Do not attempt redirect for hierarchical post types. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
if ( is_post_type_hierarchical( $post_type ) ) { |
0 | 1077 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
} |
0 | 1079 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
$id = _find_post_by_old_slug( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
if ( ! $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
$id = _find_post_by_old_date( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
* Filters the old slug redirect post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
* @since 4.9.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
* @param int $id The redirect post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
$id = apply_filters( 'old_slug_redirect_post_id', $id ); |
0 | 1094 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
if ( ! $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
$link = get_permalink( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
if ( get_query_var( 'paged' ) > 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
$link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) ); |
9 | 1103 |
} elseif ( is_embed() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
$link = user_trailingslashit( trailingslashit( $link ) . 'embed' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
} |
0 | 1106 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
* Filters the old slug redirect URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
* @param string $link The redirect URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
$link = apply_filters( 'old_slug_redirect_url', $link ); |
0 | 1115 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
if ( ! $link ) { |
0 | 1117 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
} |
0 | 1119 |
|
16 | 1120 |
wp_redirect( $link, 301 ); // Permanent redirect. |
0 | 1121 |
exit; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
* Find the post ID for redirecting an old slug. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
* @since 4.9.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* |
18 | 1131 |
* @see wp_old_slug_redirect() |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
* @param string $post_type The current post type based on the query vars. |
16 | 1135 |
* @return int The Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
function _find_post_by_old_slug( $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1142 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1143 |
* If year, monthnum, or day have been specified, make our query more precise |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1144 |
* just in case there are multiple identical _wp_old_slug values. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1145 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
if ( get_query_var( 'year' ) ) { |
9 | 1147 |
$query .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
if ( get_query_var( 'monthnum' ) ) { |
9 | 1150 |
$query .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
if ( get_query_var( 'day' ) ) { |
9 | 1153 |
$query .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1156 |
$key = md5( $query ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1157 |
$last_changed = wp_cache_get_last_changed( 'posts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1158 |
$cache_key = "find_post_by_old_slug:$key:$last_changed"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1159 |
$cache = wp_cache_get( $cache_key, 'post-queries' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1160 |
if ( false !== $cache ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1161 |
$id = $cache; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1162 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1163 |
$id = (int) $wpdb->get_var( $query ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1164 |
wp_cache_set( $cache_key, $id, 'post-queries' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1165 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
return $id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* Find the post ID for redirecting an old date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* @since 4.9.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
* |
18 | 1176 |
* @see wp_old_slug_redirect() |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
* @param string $post_type The current post type based on the query vars. |
16 | 1180 |
* @return int The Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
function _find_post_by_old_date( $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
$date_query = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
if ( get_query_var( 'year' ) ) { |
9 | 1187 |
$date_query .= $wpdb->prepare( ' AND YEAR(pm_date.meta_value) = %d', get_query_var( 'year' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
if ( get_query_var( 'monthnum' ) ) { |
9 | 1190 |
$date_query .= $wpdb->prepare( ' AND MONTH(pm_date.meta_value) = %d', get_query_var( 'monthnum' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
if ( get_query_var( 'day' ) ) { |
9 | 1193 |
$date_query .= $wpdb->prepare( ' AND DAYOFMONTH(pm_date.meta_value) = %d', get_query_var( 'day' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
$id = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
if ( $date_query ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1198 |
$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1199 |
$key = md5( $query ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1200 |
$last_changed = wp_cache_get_last_changed( 'posts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1201 |
$cache_key = "find_post_by_old_date:$key:$last_changed"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1202 |
$cache = wp_cache_get( $cache_key, 'post-queries' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1203 |
if ( false !== $cache ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1204 |
$id = $cache; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1205 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1206 |
$id = (int) $wpdb->get_var( $query ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1207 |
if ( ! $id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1208 |
// Check to see if an old slug matches the old date. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1209 |
$id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id AND post_type = %s AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, $post_type, get_query_var( 'name' ) ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1210 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
1211 |
wp_cache_set( $cache_key, $id, 'post-queries' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
return $id; |
0 | 1216 |
} |
1217 |
||
1218 |
/** |
|
1219 |
* Set up global post data. |
|
1220 |
* |
|
1221 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
* @since 4.4.0 Added the ability to pass a post ID to `$post`. |
0 | 1223 |
* |
16 | 1224 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
0 | 1227 |
* @return bool True when finished. |
1228 |
*/ |
|
1229 |
function setup_postdata( $post ) { |
|
5 | 1230 |
global $wp_query; |
1231 |
||
1232 |
if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { |
|
1233 |
return $wp_query->setup_postdata( $post ); |
|
0 | 1234 |
} |
1235 |
||
5 | 1236 |
return false; |
0 | 1237 |
} |
9 | 1238 |
|
1239 |
/** |
|
1240 |
* Generates post data. |
|
1241 |
* |
|
1242 |
* @since 5.2.0 |
|
1243 |
* |
|
16 | 1244 |
* @global WP_Query $wp_query WordPress Query object. |
9 | 1245 |
* |
1246 |
* @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
|
18 | 1247 |
* @return array|false Elements of post, or false on failure. |
9 | 1248 |
*/ |
1249 |
function generate_postdata( $post ) { |
|
1250 |
global $wp_query; |
|
1251 |
||
1252 |
if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { |
|
1253 |
return $wp_query->generate_postdata( $post ); |
|
1254 |
} |
|
1255 |
||
1256 |
return false; |
|
1257 |
} |