mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
class-wp-query.php
4933 lines (4340 loc) · 148 KB
/
class-wp-query.php
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Query API: WP_Query class
*
* @package WordPress
* @subpackage Query
* @since 4.7.0
*/
/**
* The WordPress Query class.
*
* @link https://developer.wordpress.org/reference/classes/wp_query/
*
* @since 1.5.0
* @since 4.5.0 Removed the `$comments_popup` property.
*/
#[AllowDynamicProperties]
class WP_Query {
/**
* Query vars set by the user.
*
* @since 1.5.0
* @var array
*/
public $query;
/**
* Query vars, after parsing.
*
* @since 1.5.0
* @var array
*/
public $query_vars = array();
/**
* Taxonomy query, as passed to get_tax_sql().
*
* @since 3.1.0
* @var WP_Tax_Query A taxonomy query instance.
*/
public $tax_query;
/**
* Metadata query container.
*
* @since 3.2.0
* @var WP_Meta_Query A meta query instance.
*/
public $meta_query = false;
/**
* Date query container.
*
* @since 3.7.0
* @var WP_Date_Query A date query instance.
*/
public $date_query = false;
/**
* Holds the data for a single object that is queried.
*
* Holds the contents of a post, page, category, attachment.
*
* @since 1.5.0
* @var WP_Term|WP_Post_Type|WP_Post|WP_User|null
*/
public $queried_object;
/**
* The ID of the queried object.
*
* @since 1.5.0
* @var int
*/
public $queried_object_id;
/**
* SQL for the database query.
*
* @since 2.0.1
* @var string
*/
public $request;
/**
* Array of post objects or post IDs.
*
* @since 1.5.0
* @var WP_Post[]|int[]
*/
public $posts;
/**
* The number of posts for the current query.
*
* @since 1.5.0
* @var int
*/
public $post_count = 0;
/**
* Index of the current item in the loop.
*
* @since 1.5.0
* @var int
*/
public $current_post = -1;
/**
* Whether the caller is before the loop.
*
* @since 6.3.0
* @var bool
*/
public $before_loop = true;
/**
* Whether the loop has started and the caller is in the loop.
*
* @since 2.0.0
* @var bool
*/
public $in_the_loop = false;
/**
* The current post.
*
* This property does not get populated when the `fields` argument is set to
* `ids` or `id=>parent`.
*
* @since 1.5.0
* @var WP_Post|null
*/
public $post;
/**
* The list of comments for current post.
*
* @since 2.2.0
* @var WP_Comment[]
*/
public $comments;
/**
* The number of comments for the posts.
*
* @since 2.2.0
* @var int
*/
public $comment_count = 0;
/**
* The index of the comment in the comment loop.
*
* @since 2.2.0
* @var int
*/
public $current_comment = -1;
/**
* Current comment object.
*
* @since 2.2.0
* @var WP_Comment
*/
public $comment;
/**
* The number of found posts for the current query.
*
* If limit clause was not used, equals $post_count.
*
* @since 2.1.0
* @var int
*/
public $found_posts = 0;
/**
* The number of pages.
*
* @since 2.1.0
* @var int
*/
public $max_num_pages = 0;
/**
* The number of comment pages.
*
* @since 2.7.0
* @var int
*/
public $max_num_comment_pages = 0;
/**
* Signifies whether the current query is for a single post.
*
* @since 1.5.0
* @var bool
*/
public $is_single = false;
/**
* Signifies whether the current query is for a preview.
*
* @since 2.0.0
* @var bool
*/
public $is_preview = false;
/**
* Signifies whether the current query is for a page.
*
* @since 1.5.0
* @var bool
*/
public $is_page = false;
/**
* Signifies whether the current query is for an archive.
*
* @since 1.5.0
* @var bool
*/
public $is_archive = false;
/**
* Signifies whether the current query is for a date archive.
*
* @since 1.5.0
* @var bool
*/
public $is_date = false;
/**
* Signifies whether the current query is for a year archive.
*
* @since 1.5.0
* @var bool
*/
public $is_year = false;
/**
* Signifies whether the current query is for a month archive.
*
* @since 1.5.0
* @var bool
*/
public $is_month = false;
/**
* Signifies whether the current query is for a day archive.
*
* @since 1.5.0
* @var bool
*/
public $is_day = false;
/**
* Signifies whether the current query is for a specific time.
*
* @since 1.5.0
* @var bool
*/
public $is_time = false;
/**
* Signifies whether the current query is for an author archive.
*
* @since 1.5.0
* @var bool
*/
public $is_author = false;
/**
* Signifies whether the current query is for a category archive.
*
* @since 1.5.0
* @var bool
*/
public $is_category = false;
/**
* Signifies whether the current query is for a tag archive.
*
* @since 2.3.0
* @var bool
*/
public $is_tag = false;
/**
* Signifies whether the current query is for a taxonomy archive.
*
* @since 2.5.0
* @var bool
*/
public $is_tax = false;
/**
* Signifies whether the current query is for a search.
*
* @since 1.5.0
* @var bool
*/
public $is_search = false;
/**
* Signifies whether the current query is for a feed.
*
* @since 1.5.0
* @var bool
*/
public $is_feed = false;
/**
* Signifies whether the current query is for a comment feed.
*
* @since 2.2.0
* @var bool
*/
public $is_comment_feed = false;
/**
* Signifies whether the current query is for trackback endpoint call.
*
* @since 1.5.0
* @var bool
*/
public $is_trackback = false;
/**
* Signifies whether the current query is for the site homepage.
*
* @since 1.5.0
* @var bool
*/
public $is_home = false;
/**
* Signifies whether the current query is for the Privacy Policy page.
*
* @since 5.2.0
* @var bool
*/
public $is_privacy_policy = false;
/**
* Signifies whether the current query couldn't find anything.
*
* @since 1.5.0
* @var bool
*/
public $is_404 = false;
/**
* Signifies whether the current query is for an embed.
*
* @since 4.4.0
* @var bool
*/
public $is_embed = false;
/**
* Signifies whether the current query is for a paged result and not for the first page.
*
* @since 1.5.0
* @var bool
*/
public $is_paged = false;
/**
* Signifies whether the current query is for an administrative interface page.
*
* @since 1.5.0
* @var bool
*/
public $is_admin = false;
/**
* Signifies whether the current query is for an attachment page.
*
* @since 2.0.0
* @var bool
*/
public $is_attachment = false;
/**
* Signifies whether the current query is for an existing single post of any post type
* (post, attachment, page, custom post types).
*
* @since 2.1.0
* @var bool
*/
public $is_singular = false;
/**
* Signifies whether the current query is for the robots.txt file.
*
* @since 2.1.0
* @var bool
*/
public $is_robots = false;
/**
* Signifies whether the current query is for the favicon.ico file.
*
* @since 5.4.0
* @var bool
*/
public $is_favicon = false;
/**
* Signifies whether the current query is for the page_for_posts page.
*
* Basically, the homepage if the option isn't set for the static homepage.
*
* @since 2.1.0
* @var bool
*/
public $is_posts_page = false;
/**
* Signifies whether the current query is for a post type archive.
*
* @since 3.1.0
* @var bool
*/
public $is_post_type_archive = false;
/**
* Stores the ->query_vars state like md5(serialize( $this->query_vars ) ) so we know
* whether we have to re-parse because something has changed
*
* @since 3.1.0
* @var bool|string
*/
private $query_vars_hash = false;
/**
* Whether query vars have changed since the initial parse_query() call. Used to catch modifications to query vars made
* via pre_get_posts hooks.
*
* @since 3.1.1
*/
private $query_vars_changed = true;
/**
* Set if post thumbnails are cached
*
* @since 3.2.0
* @var bool
*/
public $thumbnails_cached = false;
/**
* Controls whether an attachment query should include filenames or not.
*
* @since 6.0.3
* @var bool
*/
protected $allow_query_attachment_by_filename = false;
/**
* Cached list of search stopwords.
*
* @since 3.7.0
* @var array
*/
private $stopwords;
private $compat_fields = array( 'query_vars_hash', 'query_vars_changed' );
private $compat_methods = array( 'init_query_flags', 'parse_tax_query' );
/**
* Resets query flags to false.
*
* The query flags are what page info WordPress was able to figure out.
*
* @since 2.0.0
*/
private function init_query_flags() {
$this->is_single = false;
$this->is_preview = false;
$this->is_page = false;
$this->is_archive = false;
$this->is_date = false;
$this->is_year = false;
$this->is_month = false;
$this->is_day = false;
$this->is_time = false;
$this->is_author = false;
$this->is_category = false;
$this->is_tag = false;
$this->is_tax = false;
$this->is_search = false;
$this->is_feed = false;
$this->is_comment_feed = false;
$this->is_trackback = false;
$this->is_home = false;
$this->is_privacy_policy = false;
$this->is_404 = false;
$this->is_paged = false;
$this->is_admin = false;
$this->is_attachment = false;
$this->is_singular = false;
$this->is_robots = false;
$this->is_favicon = false;
$this->is_posts_page = false;
$this->is_post_type_archive = false;
}
/**
* Initiates object properties and sets default values.
*
* @since 1.5.0
*/
public function init() {
unset( $this->posts );
unset( $this->query );
$this->query_vars = array();
unset( $this->queried_object );
unset( $this->queried_object_id );
$this->post_count = 0;
$this->current_post = -1;
$this->in_the_loop = false;
$this->before_loop = true;
unset( $this->request );
unset( $this->post );
unset( $this->comments );
unset( $this->comment );
$this->comment_count = 0;
$this->current_comment = -1;
$this->found_posts = 0;
$this->max_num_pages = 0;
$this->max_num_comment_pages = 0;
$this->init_query_flags();
}
/**
* Reparses the query vars.
*
* @since 1.5.0
*/
public function parse_query_vars() {
$this->parse_query();
}
/**
* Fills in the query variables, which do not exist within the parameter.
*
* @since 2.1.0
* @since 4.5.0 Removed the `comments_popup` public query variable.
*
* @param array $query_vars Defined query variables.
* @return array Complete query variables with undefined ones filled in empty.
*/
public function fill_query_vars( $query_vars ) {
$keys = array(
'error',
'm',
'p',
'post_parent',
'subpost',
'subpost_id',
'attachment',
'attachment_id',
'name',
'pagename',
'page_id',
'second',
'minute',
'hour',
'day',
'monthnum',
'year',
'w',
'category_name',
'tag',
'cat',
'tag_id',
'author',
'author_name',
'feed',
'tb',
'paged',
'meta_key',
'meta_value',
'preview',
's',
'sentence',
'title',
'fields',
'menu_order',
'embed',
);
foreach ( $keys as $key ) {
if ( ! isset( $query_vars[ $key ] ) ) {
$query_vars[ $key ] = '';
}
}
$array_keys = array(
'category__in',
'category__not_in',
'category__and',
'post__in',
'post__not_in',
'post_name__in',
'tag__in',
'tag__not_in',
'tag__and',
'tag_slug__in',
'tag_slug__and',
'post_parent__in',
'post_parent__not_in',
'author__in',
'author__not_in',
'search_columns',
);
foreach ( $array_keys as $key ) {
if ( ! isset( $query_vars[ $key ] ) ) {
$query_vars[ $key ] = array();
}
}
return $query_vars;
}
/**
* Parses a query string and sets query type booleans.
*
* @since 1.5.0
* @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's
* array key to `$orderby`.
* @since 4.4.0 Introduced `$post_name__in` and `$title` parameters. `$s` was updated to support excluded
* search terms, by prepending a hyphen.
* @since 4.5.0 Removed the `$comments_popup` parameter.
* Introduced the `$comment_status` and `$ping_status` parameters.
* Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts.
* @since 4.6.0 Added 'post_name__in' support for `$orderby`. Introduced the `$lazy_load_term_meta` argument.
* @since 4.9.0 Introduced the `$comment_count` parameter.
* @since 5.1.0 Introduced the `$meta_compare_key` parameter.
* @since 5.3.0 Introduced the `$meta_type_key` parameter.
* @since 6.1.0 Introduced the `$update_menu_item_cache` parameter.
* @since 6.2.0 Introduced the `$search_columns` parameter.
*
* @param string|array $query {
* Optional. Array or string of Query parameters.
*
* @type int $attachment_id Attachment post ID. Used for 'attachment' post_type.
* @type int|string $author Author ID, or comma-separated list of IDs.
* @type string $author_name User 'user_nicename'.
* @type int[] $author__in An array of author IDs to query from.
* @type int[] $author__not_in An array of author IDs not to query from.
* @type bool $cache_results Whether to cache post information. Default true.
* @type int|string $cat Category ID or comma-separated list of IDs (this or any children).
* @type int[] $category__and An array of category IDs (AND in).
* @type int[] $category__in An array of category IDs (OR in, no children).
* @type int[] $category__not_in An array of category IDs (NOT in).
* @type string $category_name Use category slug (not name, this or any children).
* @type array|int $comment_count Filter results by comment count. Provide an integer to match
* comment count exactly. Provide an array with integer 'value'
* and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to
* compare against comment_count in a specific way.
* @type string $comment_status Comment status.
* @type int $comments_per_page The number of comments to return per page.
* Default 'comments_per_page' option.
* @type array $date_query An associative array of WP_Date_Query arguments.
* See WP_Date_Query::__construct().
* @type int $day Day of the month. Default empty. Accepts numbers 1-31.
* @type bool $exact Whether to search by exact keyword. Default false.
* @type string $fields Post fields to query for. Accepts:
* - '' Returns an array of complete post objects (`WP_Post[]`).
* - 'ids' Returns an array of post IDs (`int[]`).
* - 'id=>parent' Returns an associative array of parent post IDs,
* keyed by post ID (`int[]`).
* Default ''.
* @type int $hour Hour of the day. Default empty. Accepts numbers 0-23.
* @type int|bool $ignore_sticky_posts Whether to ignore sticky posts or not. Setting this to false
* excludes stickies from 'post__in'. Accepts 1|true, 0|false.
* Default false.
* @type int $m Combination YearMonth. Accepts any four-digit year and month
* numbers 01-12. Default empty.
* @type string|string[] $meta_key Meta key or keys to filter by.
* @type string|string[] $meta_value Meta value or values to filter by.
* @type string $meta_compare MySQL operator used for comparing the meta value.
* See WP_Meta_Query::__construct() for accepted values and default value.
* @type string $meta_compare_key MySQL operator used for comparing the meta key.
* See WP_Meta_Query::__construct() for accepted values and default value.
* @type string $meta_type MySQL data type that the meta_value column will be CAST to for comparisons.
* See WP_Meta_Query::__construct() for accepted values and default value.
* @type string $meta_type_key MySQL data type that the meta_key column will be CAST to for comparisons.
* See WP_Meta_Query::__construct() for accepted values and default value.
* @type array $meta_query An associative array of WP_Meta_Query arguments.
* See WP_Meta_Query::__construct() for accepted values.
* @type int $menu_order The menu order of the posts.
* @type int $minute Minute of the hour. Default empty. Accepts numbers 0-59.
* @type int $monthnum The two-digit month. Default empty. Accepts numbers 1-12.
* @type string $name Post slug.
* @type bool $nopaging Show all posts (true) or paginate (false). Default false.
* @type bool $no_found_rows Whether to skip counting the total rows found. Enabling can improve
* performance. Default false.
* @type int $offset The number of posts to offset before retrieval.
* @type string $order Designates ascending or descending order of posts. Default 'DESC'.
* Accepts 'ASC', 'DESC'.
* @type string|array $orderby Sort retrieved posts by parameter. One or more options may be passed.
* To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be
* also be defined. To sort by a specific `$meta_query` clause, use that
* clause's array key. Accepts:
* - 'none'
* - 'name'
* - 'author'
* - 'date'
* - 'title'
* - 'modified'
* - 'menu_order'
* - 'parent'
* - 'ID'
* - 'rand'
* - 'relevance'
* - 'RAND(x)' (where 'x' is an integer seed value)
* - 'comment_count'
* - 'meta_value'
* - 'meta_value_num'
* - 'post__in'
* - 'post_name__in'
* - 'post_parent__in'
* - The array keys of `$meta_query`.
* Default is 'date', except when a search is being performed, when
* the default is 'relevance'.
* @type int $p Post ID.
* @type int $page Show the number of posts that would show up on page X of a
* static front page.
* @type int $paged The number of the current page.
* @type int $page_id Page ID.
* @type string $pagename Page slug.
* @type string $perm Show posts if user has the appropriate capability.
* @type string $ping_status Ping status.
* @type int[] $post__in An array of post IDs to retrieve, sticky posts will be included.
* @type int[] $post__not_in An array of post IDs not to retrieve. Note: a string of comma-
* separated IDs will NOT work.
* @type string $post_mime_type The mime type of the post. Used for 'attachment' post_type.
* @type string[] $post_name__in An array of post slugs that results must match.
* @type int $post_parent Page ID to retrieve child pages for. Use 0 to only retrieve
* top-level pages.
* @type int[] $post_parent__in An array containing parent page IDs to query child pages from.
* @type int[] $post_parent__not_in An array containing parent page IDs not to query child pages from.
* @type string|string[] $post_type A post type slug (string) or array of post type slugs.
* Default 'any' if using 'tax_query'.
* @type string|string[] $post_status A post status (string) or array of post statuses.
* @type int $posts_per_page The number of posts to query for. Use -1 to request all posts.
* @type int $posts_per_archive_page The number of posts to query for by archive page. Overrides
* 'posts_per_page' when is_archive(), or is_search() are true.
* @type string $s Search keyword(s). Prepending a term with a hyphen will
* exclude posts matching that term. Eg, 'pillow -sofa' will
* return posts containing 'pillow' but not 'sofa'. The
* character used for exclusion can be modified using the
* the 'wp_query_search_exclusion_prefix' filter.
* @type string[] $search_columns Array of column names to be searched. Accepts 'post_title',
* 'post_excerpt' and 'post_content'. Default empty array.
* @type int $second Second of the minute. Default empty. Accepts numbers 0-59.
* @type bool $sentence Whether to search by phrase. Default false.
* @type bool $suppress_filters Whether to suppress filters. Default false.
* @type string $tag Tag slug. Comma-separated (either), Plus-separated (all).
* @type int[] $tag__and An array of tag IDs (AND in).
* @type int[] $tag__in An array of tag IDs (OR in).
* @type int[] $tag__not_in An array of tag IDs (NOT in).
* @type int $tag_id Tag id or comma-separated list of IDs.
* @type string[] $tag_slug__and An array of tag slugs (AND in).
* @type string[] $tag_slug__in An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
* true. Note: a string of comma-separated IDs will NOT work.
* @type array $tax_query An associative array of WP_Tax_Query arguments.
* See WP_Tax_Query::__construct().
* @type string $title Post title.
* @type bool $update_post_meta_cache Whether to update the post meta cache. Default true.
* @type bool $update_post_term_cache Whether to update the post term cache. Default true.
* @type bool $update_menu_item_cache Whether to update the menu item cache. Default false.
* @type bool $lazy_load_term_meta Whether to lazy-load term meta. Setting to false will
* disable cache priming for term meta, so that each
* get_term_meta() call will hit the database.
* Defaults to the value of `$update_post_term_cache`.
* @type int $w The week number of the year. Default empty. Accepts numbers 0-53.
* @type int $year The four-digit year. Default empty. Accepts any four-digit year.
* }
*/
public function parse_query( $query = '' ) {
if ( ! empty( $query ) ) {
$this->init();
$this->query = wp_parse_args( $query );
$this->query_vars = $this->query;
} elseif ( ! isset( $this->query ) ) {
$this->query = $this->query_vars;
}
$this->query_vars = $this->fill_query_vars( $this->query_vars );
$qv = &$this->query_vars;
$this->query_vars_changed = true;
if ( ! empty( $qv['robots'] ) ) {
$this->is_robots = true;
} elseif ( ! empty( $qv['favicon'] ) ) {
$this->is_favicon = true;
}
if ( ! is_scalar( $qv['p'] ) || (int) $qv['p'] < 0 ) {
$qv['p'] = 0;
$qv['error'] = '404';
} else {
$qv['p'] = (int) $qv['p'];
}
$qv['page_id'] = is_scalar( $qv['page_id'] ) ? absint( $qv['page_id'] ) : 0;
$qv['year'] = is_scalar( $qv['year'] ) ? absint( $qv['year'] ) : 0;
$qv['monthnum'] = is_scalar( $qv['monthnum'] ) ? absint( $qv['monthnum'] ) : 0;
$qv['day'] = is_scalar( $qv['day'] ) ? absint( $qv['day'] ) : 0;
$qv['w'] = is_scalar( $qv['w'] ) ? absint( $qv['w'] ) : 0;
$qv['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : '';
$qv['paged'] = is_scalar( $qv['paged'] ) ? absint( $qv['paged'] ) : 0;
$qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // Array or comma-separated list of positive or negative integers.
$qv['author'] = is_scalar( $qv['author'] ) ? preg_replace( '|[^0-9,-]|', '', $qv['author'] ) : ''; // Comma-separated list of positive or negative integers.
$qv['pagename'] = is_scalar( $qv['pagename'] ) ? trim( $qv['pagename'] ) : '';
$qv['name'] = is_scalar( $qv['name'] ) ? trim( $qv['name'] ) : '';
$qv['title'] = is_scalar( $qv['title'] ) ? trim( $qv['title'] ) : '';
if ( is_scalar( $qv['hour'] ) && '' !== $qv['hour'] ) {
$qv['hour'] = absint( $qv['hour'] );
} else {
$qv['hour'] = '';
}
if ( is_scalar( $qv['minute'] ) && '' !== $qv['minute'] ) {
$qv['minute'] = absint( $qv['minute'] );
} else {
$qv['minute'] = '';
}
if ( is_scalar( $qv['second'] ) && '' !== $qv['second'] ) {
$qv['second'] = absint( $qv['second'] );
} else {
$qv['second'] = '';
}
if ( is_scalar( $qv['menu_order'] ) && '' !== $qv['menu_order'] ) {
$qv['menu_order'] = absint( $qv['menu_order'] );
} else {
$qv['menu_order'] = '';
}
// Fairly large, potentially too large, upper bound for search string lengths.
if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) {
$qv['s'] = '';
}
// Compat. Map subpost to attachment.
if ( is_scalar( $qv['subpost'] ) && '' != $qv['subpost'] ) {
$qv['attachment'] = $qv['subpost'];
}
if ( is_scalar( $qv['subpost_id'] ) && '' != $qv['subpost_id'] ) {
$qv['attachment_id'] = $qv['subpost_id'];
}
$qv['attachment_id'] = is_scalar( $qv['attachment_id'] ) ? absint( $qv['attachment_id'] ) : 0;
if ( ( '' !== $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {
$this->is_single = true;
$this->is_attachment = true;
} elseif ( '' !== $qv['name'] ) {
$this->is_single = true;
} elseif ( $qv['p'] ) {
$this->is_single = true;
} elseif ( '' !== $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
$this->is_page = true;
$this->is_single = false;
} else {
// Look for archive queries. Dates, categories, authors, search, post type archives.
if ( isset( $this->query['s'] ) ) {
$this->is_search = true;
}
if ( '' !== $qv['second'] ) {
$this->is_time = true;
$this->is_date = true;
}
if ( '' !== $qv['minute'] ) {
$this->is_time = true;
$this->is_date = true;
}
if ( '' !== $qv['hour'] ) {
$this->is_time = true;
$this->is_date = true;
}
if ( $qv['day'] ) {
if ( ! $this->is_date ) {
$date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] );
if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) {
$qv['error'] = '404';
} else {
$this->is_day = true;
$this->is_date = true;
}
}
}
if ( $qv['monthnum'] ) {
if ( ! $this->is_date ) {
if ( 12 < $qv['monthnum'] ) {
$qv['error'] = '404';
} else {
$this->is_month = true;
$this->is_date = true;
}
}
}
if ( $qv['year'] ) {
if ( ! $this->is_date ) {
$this->is_year = true;
$this->is_date = true;
}
}
if ( $qv['m'] ) {
$this->is_date = true;
if ( strlen( $qv['m'] ) > 9 ) {
$this->is_time = true;
} elseif ( strlen( $qv['m'] ) > 7 ) {
$this->is_day = true;
} elseif ( strlen( $qv['m'] ) > 5 ) {
$this->is_month = true;
} else {
$this->is_year = true;
}
}
if ( $qv['w'] ) {
$this->is_date = true;
}
$this->query_vars_hash = false;
$this->parse_tax_query( $qv );
foreach ( $this->tax_query->queries as $tax_query ) {
if ( ! is_array( $tax_query ) ) {
continue;
}
if ( isset( $tax_query['operator'] ) && 'NOT IN' !== $tax_query['operator'] ) {
switch ( $tax_query['taxonomy'] ) {
case 'category':
$this->is_category = true;
break;
case 'post_tag':
$this->is_tag = true;
break;
default:
$this->is_tax = true;
}
}
}
unset( $tax_query );
if ( empty( $qv['author'] ) || ( '0' == $qv['author'] ) ) {
$this->is_author = false;
} else {
$this->is_author = true;
}
if ( '' !== $qv['author_name'] ) {
$this->is_author = true;
}
if ( ! empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
$post_type_obj = get_post_type_object( $qv['post_type'] );
if ( ! empty( $post_type_obj->has_archive ) ) {
$this->is_post_type_archive = true;
}
}
if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) {
$this->is_archive = true;
}
}
if ( '' != $qv['feed'] ) {
$this->is_feed = true;
}
if ( '' != $qv['embed'] ) {
$this->is_embed = true;
}