Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like WP_Query often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WP_Query, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class WP_Query { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Query vars set by the user |
||
| 22 | * |
||
| 23 | * @since 1.5.0 |
||
| 24 | * @access public |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | public $query; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Query vars, after parsing |
||
| 31 | * |
||
| 32 | * @since 1.5.0 |
||
| 33 | * @access public |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | public $query_vars = array(); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Taxonomy query, as passed to get_tax_sql() |
||
| 40 | * |
||
| 41 | * @since 3.1.0 |
||
| 42 | * @access public |
||
| 43 | * @var object WP_Tax_Query |
||
| 44 | */ |
||
| 45 | public $tax_query; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Metadata query container |
||
| 49 | * |
||
| 50 | * @since 3.2.0 |
||
| 51 | * @access public |
||
| 52 | * @var object WP_Meta_Query |
||
| 53 | */ |
||
| 54 | public $meta_query = false; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Date query container |
||
| 58 | * |
||
| 59 | * @since 3.7.0 |
||
| 60 | * @access public |
||
| 61 | * @var object WP_Date_Query |
||
| 62 | */ |
||
| 63 | public $date_query = false; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Holds the data for a single object that is queried. |
||
| 67 | * |
||
| 68 | * Holds the contents of a post, page, category, attachment. |
||
| 69 | * |
||
| 70 | * @since 1.5.0 |
||
| 71 | * @access public |
||
| 72 | * @var object|array |
||
| 73 | */ |
||
| 74 | public $queried_object; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The ID of the queried object. |
||
| 78 | * |
||
| 79 | * @since 1.5.0 |
||
| 80 | * @access public |
||
| 81 | * @var int |
||
| 82 | */ |
||
| 83 | public $queried_object_id; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Get post database query. |
||
| 87 | * |
||
| 88 | * @since 2.0.1 |
||
| 89 | * @access public |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | public $request; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * List of posts. |
||
| 96 | * |
||
| 97 | * @since 1.5.0 |
||
| 98 | * @access public |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | public $posts; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The amount of posts for the current query. |
||
| 105 | * |
||
| 106 | * @since 1.5.0 |
||
| 107 | * @access public |
||
| 108 | * @var int |
||
| 109 | */ |
||
| 110 | public $post_count = 0; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Index of the current item in the loop. |
||
| 114 | * |
||
| 115 | * @since 1.5.0 |
||
| 116 | * @access public |
||
| 117 | * @var int |
||
| 118 | */ |
||
| 119 | public $current_post = -1; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Whether the loop has started and the caller is in the loop. |
||
| 123 | * |
||
| 124 | * @since 2.0.0 |
||
| 125 | * @access public |
||
| 126 | * @var bool |
||
| 127 | */ |
||
| 128 | public $in_the_loop = false; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * The current post. |
||
| 132 | * |
||
| 133 | * @since 1.5.0 |
||
| 134 | * @access public |
||
| 135 | * @var WP_Post |
||
| 136 | */ |
||
| 137 | public $post; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * The list of comments for current post. |
||
| 141 | * |
||
| 142 | * @since 2.2.0 |
||
| 143 | * @access public |
||
| 144 | * @var array |
||
| 145 | */ |
||
| 146 | public $comments; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * The amount of comments for the posts. |
||
| 150 | * |
||
| 151 | * @since 2.2.0 |
||
| 152 | * @access public |
||
| 153 | * @var int |
||
| 154 | */ |
||
| 155 | public $comment_count = 0; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * The index of the comment in the comment loop. |
||
| 159 | * |
||
| 160 | * @since 2.2.0 |
||
| 161 | * @access public |
||
| 162 | * @var int |
||
| 163 | */ |
||
| 164 | public $current_comment = -1; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Current comment ID. |
||
| 168 | * |
||
| 169 | * @since 2.2.0 |
||
| 170 | * @access public |
||
| 171 | * @var int |
||
| 172 | */ |
||
| 173 | public $comment; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * The amount of found posts for the current query. |
||
| 177 | * |
||
| 178 | * If limit clause was not used, equals $post_count. |
||
| 179 | * |
||
| 180 | * @since 2.1.0 |
||
| 181 | * @access public |
||
| 182 | * @var int |
||
| 183 | */ |
||
| 184 | public $found_posts = 0; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * The amount of pages. |
||
| 188 | * |
||
| 189 | * @since 2.1.0 |
||
| 190 | * @access public |
||
| 191 | * @var int |
||
| 192 | */ |
||
| 193 | public $max_num_pages = 0; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * The amount of comment pages. |
||
| 197 | * |
||
| 198 | * @since 2.7.0 |
||
| 199 | * @access public |
||
| 200 | * @var int |
||
| 201 | */ |
||
| 202 | public $max_num_comment_pages = 0; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Set if query is single post. |
||
| 206 | * |
||
| 207 | * @since 1.5.0 |
||
| 208 | * @access public |
||
| 209 | * @var bool |
||
| 210 | */ |
||
| 211 | public $is_single = false; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Set if query is preview of blog. |
||
| 215 | * |
||
| 216 | * @since 2.0.0 |
||
| 217 | * @access public |
||
| 218 | * @var bool |
||
| 219 | */ |
||
| 220 | public $is_preview = false; |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Set if query returns a page. |
||
| 224 | * |
||
| 225 | * @since 1.5.0 |
||
| 226 | * @access public |
||
| 227 | * @var bool |
||
| 228 | */ |
||
| 229 | public $is_page = false; |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Set if query is an archive list. |
||
| 233 | * |
||
| 234 | * @since 1.5.0 |
||
| 235 | * @access public |
||
| 236 | * @var bool |
||
| 237 | */ |
||
| 238 | public $is_archive = false; |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Set if query is part of a date. |
||
| 242 | * |
||
| 243 | * @since 1.5.0 |
||
| 244 | * @access public |
||
| 245 | * @var bool |
||
| 246 | */ |
||
| 247 | public $is_date = false; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Set if query contains a year. |
||
| 251 | * |
||
| 252 | * @since 1.5.0 |
||
| 253 | * @access public |
||
| 254 | * @var bool |
||
| 255 | */ |
||
| 256 | public $is_year = false; |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Set if query contains a month. |
||
| 260 | * |
||
| 261 | * @since 1.5.0 |
||
| 262 | * @access public |
||
| 263 | * @var bool |
||
| 264 | */ |
||
| 265 | public $is_month = false; |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Set if query contains a day. |
||
| 269 | * |
||
| 270 | * @since 1.5.0 |
||
| 271 | * @access public |
||
| 272 | * @var bool |
||
| 273 | */ |
||
| 274 | public $is_day = false; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Set if query contains time. |
||
| 278 | * |
||
| 279 | * @since 1.5.0 |
||
| 280 | * @access public |
||
| 281 | * @var bool |
||
| 282 | */ |
||
| 283 | public $is_time = false; |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Set if query contains an author. |
||
| 287 | * |
||
| 288 | * @since 1.5.0 |
||
| 289 | * @access public |
||
| 290 | * @var bool |
||
| 291 | */ |
||
| 292 | public $is_author = false; |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Set if query contains category. |
||
| 296 | * |
||
| 297 | * @since 1.5.0 |
||
| 298 | * @access public |
||
| 299 | * @var bool |
||
| 300 | */ |
||
| 301 | public $is_category = false; |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Set if query contains tag. |
||
| 305 | * |
||
| 306 | * @since 2.3.0 |
||
| 307 | * @access public |
||
| 308 | * @var bool |
||
| 309 | */ |
||
| 310 | public $is_tag = false; |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Set if query contains taxonomy. |
||
| 314 | * |
||
| 315 | * @since 2.5.0 |
||
| 316 | * @access public |
||
| 317 | * @var bool |
||
| 318 | */ |
||
| 319 | public $is_tax = false; |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Set if query was part of a search result. |
||
| 323 | * |
||
| 324 | * @since 1.5.0 |
||
| 325 | * @access public |
||
| 326 | * @var bool |
||
| 327 | */ |
||
| 328 | public $is_search = false; |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Set if query is feed display. |
||
| 332 | * |
||
| 333 | * @since 1.5.0 |
||
| 334 | * @access public |
||
| 335 | * @var bool |
||
| 336 | */ |
||
| 337 | public $is_feed = false; |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Set if query is comment feed display. |
||
| 341 | * |
||
| 342 | * @since 2.2.0 |
||
| 343 | * @access public |
||
| 344 | * @var bool |
||
| 345 | */ |
||
| 346 | public $is_comment_feed = false; |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Set if query is trackback. |
||
| 350 | * |
||
| 351 | * @since 1.5.0 |
||
| 352 | * @access public |
||
| 353 | * @var bool |
||
| 354 | */ |
||
| 355 | public $is_trackback = false; |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Set if query is blog homepage. |
||
| 359 | * |
||
| 360 | * @since 1.5.0 |
||
| 361 | * @access public |
||
| 362 | * @var bool |
||
| 363 | */ |
||
| 364 | public $is_home = false; |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Set if query couldn't found anything. |
||
| 368 | * |
||
| 369 | * @since 1.5.0 |
||
| 370 | * @access public |
||
| 371 | * @var bool |
||
| 372 | */ |
||
| 373 | public $is_404 = false; |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Set if query is embed. |
||
| 377 | * |
||
| 378 | * @since 4.4.0 |
||
| 379 | * @access public |
||
| 380 | * @var bool |
||
| 381 | */ |
||
| 382 | public $is_embed = false; |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Set if query is paged |
||
| 386 | * |
||
| 387 | * @since 1.5.0 |
||
| 388 | * @access public |
||
| 389 | * @var bool |
||
| 390 | */ |
||
| 391 | public $is_paged = false; |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Set if query is part of administration page. |
||
| 395 | * |
||
| 396 | * @since 1.5.0 |
||
| 397 | * @access public |
||
| 398 | * @var bool |
||
| 399 | */ |
||
| 400 | public $is_admin = false; |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Set if query is an attachment. |
||
| 404 | * |
||
| 405 | * @since 2.0.0 |
||
| 406 | * @access public |
||
| 407 | * @var bool |
||
| 408 | */ |
||
| 409 | public $is_attachment = false; |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Set if is single, is a page, or is an attachment. |
||
| 413 | * |
||
| 414 | * @since 2.1.0 |
||
| 415 | * @access public |
||
| 416 | * @var bool |
||
| 417 | */ |
||
| 418 | public $is_singular = false; |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Set if query is for robots. |
||
| 422 | * |
||
| 423 | * @since 2.1.0 |
||
| 424 | * @access public |
||
| 425 | * @var bool |
||
| 426 | */ |
||
| 427 | public $is_robots = false; |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Set if query contains posts. |
||
| 431 | * |
||
| 432 | * Basically, the homepage if the option isn't set for the static homepage. |
||
| 433 | * |
||
| 434 | * @since 2.1.0 |
||
| 435 | * @access public |
||
| 436 | * @var bool |
||
| 437 | */ |
||
| 438 | public $is_posts_page = false; |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Set if query is for a post type archive. |
||
| 442 | * |
||
| 443 | * @since 3.1.0 |
||
| 444 | * @access public |
||
| 445 | * @var bool |
||
| 446 | */ |
||
| 447 | public $is_post_type_archive = false; |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Stores the ->query_vars state like md5(serialize( $this->query_vars ) ) so we know |
||
| 451 | * whether we have to re-parse because something has changed |
||
| 452 | * |
||
| 453 | * @since 3.1.0 |
||
| 454 | * @access private |
||
| 455 | * @var bool|string |
||
| 456 | */ |
||
| 457 | private $query_vars_hash = false; |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Whether query vars have changed since the initial parse_query() call. Used to catch modifications to query vars made |
||
| 461 | * via pre_get_posts hooks. |
||
| 462 | * |
||
| 463 | * @since 3.1.1 |
||
| 464 | * @access private |
||
| 465 | */ |
||
| 466 | private $query_vars_changed = true; |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Set if post thumbnails are cached |
||
| 470 | * |
||
| 471 | * @since 3.2.0 |
||
| 472 | * @access public |
||
| 473 | * @var bool |
||
| 474 | */ |
||
| 475 | public $thumbnails_cached = false; |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Cached list of search stopwords. |
||
| 479 | * |
||
| 480 | * @since 3.7.0 |
||
| 481 | * @var array |
||
| 482 | */ |
||
| 483 | private $stopwords; |
||
| 484 | |||
| 485 | private $compat_fields = array( 'query_vars_hash', 'query_vars_changed' ); |
||
| 486 | |||
| 487 | private $compat_methods = array( 'init_query_flags', 'parse_tax_query' ); |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Resets query flags to false. |
||
| 491 | * |
||
| 492 | * The query flags are what page info WordPress was able to figure out. |
||
| 493 | * |
||
| 494 | * @since 2.0.0 |
||
| 495 | * @access private |
||
| 496 | */ |
||
| 497 | private function init_query_flags() { |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Initiates object properties and sets default values. |
||
| 528 | * |
||
| 529 | * @since 1.5.0 |
||
| 530 | * @access public |
||
| 531 | */ |
||
| 532 | public function init() { |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Reparse the query vars. |
||
| 556 | * |
||
| 557 | * @since 1.5.0 |
||
| 558 | * @access public |
||
| 559 | */ |
||
| 560 | public function parse_query_vars() { |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Fills in the query variables, which do not exist within the parameter. |
||
| 566 | * |
||
| 567 | * @since 2.1.0 |
||
| 568 | * @since 4.4.0 Removed the `comments_popup` public query variable. |
||
| 569 | * @access public |
||
| 570 | * |
||
| 571 | * @param array $array Defined query variables. |
||
| 572 | * @return array Complete query variables with undefined ones filled in empty. |
||
| 573 | */ |
||
| 574 | public function fill_query_vars($array) { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Parse a query string and set query type booleans. |
||
| 633 | * |
||
| 634 | * @since 1.5.0 |
||
| 635 | * @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's |
||
| 636 | * array key to `$orderby`. |
||
| 637 | * @since 4.4.0 Introduced `$post_name__in` and `$title` parameters. `$s` was updated to support excluded |
||
| 638 | * search terms, by prepending a hyphen. |
||
| 639 | * @since 4.5.0 Removed the `$comments_popup` parameter. |
||
| 640 | * Introduced the `$comment_status` and `$ping_status` parameters. |
||
| 641 | * Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts. |
||
| 642 | * @since 4.6.0 Added 'post_name__in' support for `$orderby`. Introduced the `$lazy_load_term_meta` argument. |
||
| 643 | * @access public |
||
| 644 | * |
||
| 645 | * @param string|array $query { |
||
| 646 | * Optional. Array or string of Query parameters. |
||
| 647 | * |
||
| 648 | * @type int $attachment_id Attachment post ID. Used for 'attachment' post_type. |
||
| 649 | * @type int|string $author Author ID, or comma-separated list of IDs. |
||
| 650 | * @type string $author_name User 'user_nicename'. |
||
| 651 | * @type array $author__in An array of author IDs to query from. |
||
| 652 | * @type array $author__not_in An array of author IDs not to query from. |
||
| 653 | * @type bool $cache_results Whether to cache post information. Default true. |
||
| 654 | * @type int|string $cat Category ID or comma-separated list of IDs (this or any children). |
||
| 655 | * @type array $category__and An array of category IDs (AND in). |
||
| 656 | * @type array $category__in An array of category IDs (OR in, no children). |
||
| 657 | * @type array $category__not_in An array of category IDs (NOT in). |
||
| 658 | * @type string $category_name Use category slug (not name, this or any children). |
||
| 659 | * @type string $comment_status Comment status. |
||
| 660 | * @type int $comments_per_page The number of comments to return per page. |
||
| 661 | * Default 'comments_per_page' option. |
||
| 662 | * @type array $date_query An associative array of WP_Date_Query arguments. |
||
| 663 | * See WP_Date_Query::__construct(). |
||
| 664 | * @type int $day Day of the month. Default empty. Accepts numbers 1-31. |
||
| 665 | * @type bool $exact Whether to search by exact keyword. Default false. |
||
| 666 | * @type string|array $fields Which fields to return. Single field or all fields (string), |
||
| 667 | * or array of fields. 'id=>parent' uses 'id' and 'post_parent'. |
||
| 668 | * Default all fields. Accepts 'ids', 'id=>parent'. |
||
| 669 | * @type int $hour Hour of the day. Default empty. Accepts numbers 0-23. |
||
| 670 | * @type int|bool $ignore_sticky_posts Whether to ignore sticky posts or not. Setting this to false |
||
| 671 | * excludes stickies from 'post__in'. Accepts 1|true, 0|false. |
||
| 672 | * Default 0|false. |
||
| 673 | * @type int $m Combination YearMonth. Accepts any four-digit year and month |
||
| 674 | * numbers 1-12. Default empty. |
||
| 675 | * @type string $meta_compare Comparison operator to test the 'meta_value'. |
||
| 676 | * @type string $meta_key Custom field key. |
||
| 677 | * @type array $meta_query An associative array of WP_Meta_Query arguments. See WP_Meta_Query. |
||
| 678 | * @type string $meta_value Custom field value. |
||
| 679 | * @type int $meta_value_num Custom field value number. |
||
| 680 | * @type int $menu_order The menu order of the posts. |
||
| 681 | * @type int $monthnum The two-digit month. Default empty. Accepts numbers 1-12. |
||
| 682 | * @type string $name Post slug. |
||
| 683 | * @type bool $nopaging Show all posts (true) or paginate (false). Default false. |
||
| 684 | * @type bool $no_found_rows Whether to skip counting the total rows found. Enabling can improve |
||
| 685 | * performance. Default false. |
||
| 686 | * @type int $offset The number of posts to offset before retrieval. |
||
| 687 | * @type string $order Designates ascending or descending order of posts. Default 'DESC'. |
||
| 688 | * Accepts 'ASC', 'DESC'. |
||
| 689 | * @type string|array $orderby Sort retrieved posts by parameter. One or more options may be |
||
| 690 | * passed. To use 'meta_value', or 'meta_value_num', |
||
| 691 | * 'meta_key=keyname' must be also be defined. To sort by a |
||
| 692 | * specific `$meta_query` clause, use that clause's array key. |
||
| 693 | * Accepts 'none', 'name', 'author', 'date', 'title', |
||
| 694 | * 'modified', 'menu_order', 'parent', 'ID', 'rand', |
||
| 695 | * 'relevance', 'RAND(x)' (where 'x' is an integer seed value), |
||
| 696 | * 'comment_count', 'meta_value', 'meta_value_num', 'post__in', |
||
| 697 | * 'post_name__in', 'post_parent__in', and the array keys |
||
| 698 | * of `$meta_query`. Default is 'date', except when a search |
||
| 699 | * is being performed, when the default is 'relevance'. |
||
| 700 | * |
||
| 701 | * @type int $p Post ID. |
||
| 702 | * @type int $page Show the number of posts that would show up on page X of a |
||
| 703 | * static front page. |
||
| 704 | * @type int $paged The number of the current page. |
||
| 705 | * @type int $page_id Page ID. |
||
| 706 | * @type string $pagename Page slug. |
||
| 707 | * @type string $perm Show posts if user has the appropriate capability. |
||
| 708 | * @type string $ping_status Ping status. |
||
| 709 | * @type array $post__in An array of post IDs to retrieve, sticky posts will be included |
||
| 710 | * @type string $post_mime_type The mime type of the post. Used for 'attachment' post_type. |
||
| 711 | * @type array $post__not_in An array of post IDs not to retrieve. Note: a string of comma- |
||
| 712 | * separated IDs will NOT work. |
||
| 713 | * @type int $post_parent Page ID to retrieve child pages for. Use 0 to only retrieve |
||
| 714 | * top-level pages. |
||
| 715 | * @type array $post_parent__in An array containing parent page IDs to query child pages from. |
||
| 716 | * @type array $post_parent__not_in An array containing parent page IDs not to query child pages from. |
||
| 717 | * @type string|array $post_type A post type slug (string) or array of post type slugs. |
||
| 718 | * Default 'any' if using 'tax_query'. |
||
| 719 | * @type string|array $post_status A post status (string) or array of post statuses. |
||
| 720 | * @type int $posts_per_page The number of posts to query for. Use -1 to request all posts. |
||
| 721 | * @type int $posts_per_archive_page The number of posts to query for by archive page. Overrides |
||
| 722 | * 'posts_per_page' when is_archive(), or is_search() are true. |
||
| 723 | * @type array $post_name__in An array of post slugs that results must match. |
||
| 724 | * @type string $s Search keyword(s). Prepending a term with a hyphen will |
||
| 725 | * exclude posts matching that term. Eg, 'pillow -sofa' will |
||
| 726 | * return posts containing 'pillow' but not 'sofa'. The |
||
| 727 | * character used for exclusion can be modified using the |
||
| 728 | * the 'wp_query_search_exclusion_prefix' filter. |
||
| 729 | * @type int $second Second of the minute. Default empty. Accepts numbers 0-60. |
||
| 730 | * @type bool $sentence Whether to search by phrase. Default false. |
||
| 731 | * @type bool $suppress_filters Whether to suppress filters. Default false. |
||
| 732 | * @type string $tag Tag slug. Comma-separated (either), Plus-separated (all). |
||
| 733 | * @type array $tag__and An array of tag ids (AND in). |
||
| 734 | * @type array $tag__in An array of tag ids (OR in). |
||
| 735 | * @type array $tag__not_in An array of tag ids (NOT in). |
||
| 736 | * @type int $tag_id Tag id or comma-separated list of IDs. |
||
| 737 | * @type array $tag_slug__and An array of tag slugs (AND in). |
||
| 738 | * @type array $tag_slug__in An array of tag slugs (OR in). unless 'ignore_sticky_posts' is |
||
| 739 | * true. Note: a string of comma-separated IDs will NOT work. |
||
| 740 | * @type array $tax_query An associative array of WP_Tax_Query arguments. |
||
| 741 | * See WP_Tax_Query->queries. |
||
| 742 | * @type string $title Post title. |
||
| 743 | * @type bool $update_post_meta_cache Whether to update the post meta cache. Default true. |
||
| 744 | * @type bool $update_post_term_cache Whether to update the post term cache. Default true. |
||
| 745 | * @type bool $lazy_load_term_meta Whether to lazy-load term meta. Setting to false will |
||
| 746 | * disable cache priming for term meta, so that each |
||
| 747 | * get_term_meta() call will hit the database. |
||
| 748 | * Defaults to the value of `$update_post_term_cache`. |
||
| 749 | * @type int $w The week number of the year. Default empty. Accepts numbers 0-53. |
||
| 750 | * @type int $year The four-digit year. Default empty. Accepts any four-digit year. |
||
| 751 | * } |
||
| 752 | */ |
||
| 753 | public function parse_query( $query = '' ) { |
||
| 1057 | |||
| 1058 | /** |
||
| 1059 | * Parses various taxonomy related query vars. |
||
| 1060 | * |
||
| 1061 | * For BC, this method is not marked as protected. See [28987]. |
||
| 1062 | * |
||
| 1063 | * @access protected |
||
| 1064 | * @since 3.1.0 |
||
| 1065 | * |
||
| 1066 | * @param array $q The query variables. Passed by reference. |
||
| 1067 | */ |
||
| 1068 | public function parse_tax_query( &$q ) { |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Generate SQL for the WHERE clause based on passed search terms. |
||
| 1290 | * |
||
| 1291 | * @since 3.7.0 |
||
| 1292 | * |
||
| 1293 | * @param array $q Query variables. |
||
| 1294 | * @return string WHERE clause. |
||
| 1295 | */ |
||
| 1296 | protected function parse_search( &$q ) { |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * Check if the terms are suitable for searching. |
||
| 1370 | * |
||
| 1371 | * Uses an array of stopwords (terms) that are excluded from the separate |
||
| 1372 | * term matching when searching for posts. The list of English stopwords is |
||
| 1373 | * the approximate search engines list, and is translatable. |
||
| 1374 | * |
||
| 1375 | * @since 3.7.0 |
||
| 1376 | * |
||
| 1377 | * @param array $terms Terms to check. |
||
| 1378 | * @return array Terms that are not stopwords. |
||
| 1379 | */ |
||
| 1380 | protected function parse_search_terms( $terms ) { |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Retrieve stopwords used when parsing search terms. |
||
| 1408 | * |
||
| 1409 | * @since 3.7.0 |
||
| 1410 | * |
||
| 1411 | * @return array Stopwords. |
||
| 1412 | */ |
||
| 1413 | protected function get_search_stopwords() { |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Generate SQL for the ORDER BY condition based on passed search terms. |
||
| 1444 | * |
||
| 1445 | * @param array $q Query variables. |
||
| 1446 | * @return string ORDER BY clause. |
||
| 1447 | */ |
||
| 1448 | protected function parse_search_order( &$q ) { |
||
| 1493 | |||
| 1494 | /** |
||
| 1495 | * If the passed orderby value is allowed, convert the alias to a |
||
| 1496 | * properly-prefixed orderby value. |
||
| 1497 | * |
||
| 1498 | * @since 4.0.0 |
||
| 1499 | * @access protected |
||
| 1500 | * |
||
| 1501 | * @param string $orderby Alias for the field to order by. |
||
| 1502 | * @return string|false Table-prefixed value to used in the ORDER clause. False otherwise. |
||
| 1503 | */ |
||
| 1504 | protected function parse_orderby( $orderby ) { |
||
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Parse an 'order' query variable and cast it to ASC or DESC as necessary. |
||
| 1589 | * |
||
| 1590 | * @since 4.0.0 |
||
| 1591 | * @access protected |
||
| 1592 | * |
||
| 1593 | * @param string $order The 'order' query variable. |
||
| 1594 | * @return string The sanitized 'order' query variable. |
||
| 1595 | */ |
||
| 1596 | View Code Duplication | protected function parse_order( $order ) { |
|
| 1607 | |||
| 1608 | /** |
||
| 1609 | * Sets the 404 property and saves whether query is feed. |
||
| 1610 | * |
||
| 1611 | * @since 2.0.0 |
||
| 1612 | * @access public |
||
| 1613 | */ |
||
| 1614 | public function set_404() { |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * Retrieve query variable. |
||
| 1625 | * |
||
| 1626 | * @since 1.5.0 |
||
| 1627 | * @since 3.9.0 The `$default` argument was introduced. |
||
| 1628 | * |
||
| 1629 | * @access public |
||
| 1630 | * |
||
| 1631 | * @param string $query_var Query variable key. |
||
| 1632 | * @param mixed $default Optional. Value to return if the query variable is not set. Default empty. |
||
| 1633 | * @return mixed Contents of the query variable. |
||
| 1634 | */ |
||
| 1635 | public function get( $query_var, $default = '' ) { |
||
| 1642 | |||
| 1643 | /** |
||
| 1644 | * Set query variable. |
||
| 1645 | * |
||
| 1646 | * @since 1.5.0 |
||
| 1647 | * @access public |
||
| 1648 | * |
||
| 1649 | * @param string $query_var Query variable key. |
||
| 1650 | * @param mixed $value Query variable value. |
||
| 1651 | */ |
||
| 1652 | public function set($query_var, $value) { |
||
| 1655 | |||
| 1656 | /** |
||
| 1657 | * Retrieve the posts based on query variables. |
||
| 1658 | * |
||
| 1659 | * There are a few filters and actions that can be used to modify the post |
||
| 1660 | * database query. |
||
| 1661 | * |
||
| 1662 | * @since 1.5.0 |
||
| 1663 | * @access public |
||
| 1664 | * |
||
| 1665 | * @return array List of posts. |
||
| 1666 | */ |
||
| 1667 | public function get_posts() { |
||
| 1668 | global $wpdb; |
||
| 1669 | |||
| 1670 | $this->parse_query(); |
||
| 1671 | |||
| 1672 | /** |
||
| 1673 | * Fires after the query variable object is created, but before the actual query is run. |
||
| 1674 | * |
||
| 1675 | * Note: If using conditional tags, use the method versions within the passed instance |
||
| 1676 | * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions |
||
| 1677 | * like is_main_query() test against the global $wp_query instance, not the passed one. |
||
| 1678 | * |
||
| 1679 | * @since 2.0.0 |
||
| 1680 | * |
||
| 1681 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 1682 | */ |
||
| 1683 | do_action_ref_array( 'pre_get_posts', array( &$this ) ); |
||
| 1684 | |||
| 1685 | // Shorthand. |
||
| 1686 | $q = &$this->query_vars; |
||
| 1687 | |||
| 1688 | // Fill again in case pre_get_posts unset some vars. |
||
| 1689 | $q = $this->fill_query_vars($q); |
||
| 1690 | |||
| 1691 | // Parse meta query |
||
| 1692 | $this->meta_query = new WP_Meta_Query(); |
||
| 1693 | $this->meta_query->parse_query_vars( $q ); |
||
| 1694 | |||
| 1695 | // Set a flag if a pre_get_posts hook changed the query vars. |
||
| 1696 | $hash = md5( serialize( $this->query_vars ) ); |
||
| 1697 | if ( $hash != $this->query_vars_hash ) { |
||
| 1698 | $this->query_vars_changed = true; |
||
| 1699 | $this->query_vars_hash = $hash; |
||
| 1700 | } |
||
| 1701 | unset($hash); |
||
| 1702 | |||
| 1703 | // First let's clear some variables |
||
| 1704 | $distinct = ''; |
||
| 1705 | $whichauthor = ''; |
||
| 1706 | $whichmimetype = ''; |
||
| 1707 | $where = ''; |
||
| 1708 | $limits = ''; |
||
| 1709 | $join = ''; |
||
| 1710 | $search = ''; |
||
| 1711 | $groupby = ''; |
||
| 1712 | $post_status_join = false; |
||
| 1713 | $page = 1; |
||
| 1714 | |||
| 1715 | if ( isset( $q['caller_get_posts'] ) ) { |
||
| 1716 | _deprecated_argument( 'WP_Query', '3.1.0', |
||
| 1717 | /* translators: 1: caller_get_posts, 2: ignore_sticky_posts */ |
||
| 1718 | sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), |
||
| 1719 | '<code>caller_get_posts</code>', |
||
| 1720 | '<code>ignore_sticky_posts</code>' |
||
| 1721 | ) |
||
| 1722 | ); |
||
| 1723 | |||
| 1724 | if ( ! isset( $q['ignore_sticky_posts'] ) ) { |
||
| 1725 | $q['ignore_sticky_posts'] = $q['caller_get_posts']; |
||
| 1726 | } |
||
| 1727 | } |
||
| 1728 | |||
| 1729 | if ( !isset( $q['ignore_sticky_posts'] ) ) |
||
| 1730 | $q['ignore_sticky_posts'] = false; |
||
| 1731 | |||
| 1732 | if ( !isset($q['suppress_filters']) ) |
||
| 1733 | $q['suppress_filters'] = false; |
||
| 1734 | |||
| 1735 | if ( !isset($q['cache_results']) ) { |
||
| 1736 | if ( wp_using_ext_object_cache() ) |
||
| 1737 | $q['cache_results'] = false; |
||
| 1738 | else |
||
| 1739 | $q['cache_results'] = true; |
||
| 1740 | } |
||
| 1741 | |||
| 1742 | if ( !isset($q['update_post_term_cache']) ) |
||
| 1743 | $q['update_post_term_cache'] = true; |
||
| 1744 | |||
| 1745 | if ( ! isset( $q['lazy_load_term_meta'] ) ) { |
||
| 1746 | $q['lazy_load_term_meta'] = $q['update_post_term_cache']; |
||
| 1747 | } |
||
| 1748 | |||
| 1749 | if ( !isset($q['update_post_meta_cache']) ) |
||
| 1750 | $q['update_post_meta_cache'] = true; |
||
| 1751 | |||
| 1752 | if ( !isset($q['post_type']) ) { |
||
| 1753 | if ( $this->is_search ) |
||
| 1754 | $q['post_type'] = 'any'; |
||
| 1755 | else |
||
| 1756 | $q['post_type'] = ''; |
||
| 1757 | } |
||
| 1758 | $post_type = $q['post_type']; |
||
| 1759 | if ( empty( $q['posts_per_page'] ) ) { |
||
| 1760 | $q['posts_per_page'] = get_option( 'posts_per_page' ); |
||
| 1761 | } |
||
| 1762 | if ( isset($q['showposts']) && $q['showposts'] ) { |
||
| 1763 | $q['showposts'] = (int) $q['showposts']; |
||
| 1764 | $q['posts_per_page'] = $q['showposts']; |
||
| 1765 | } |
||
| 1766 | if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) |
||
| 1767 | $q['posts_per_page'] = $q['posts_per_archive_page']; |
||
| 1768 | if ( !isset($q['nopaging']) ) { |
||
| 1769 | if ( $q['posts_per_page'] == -1 ) { |
||
| 1770 | $q['nopaging'] = true; |
||
| 1771 | } else { |
||
| 1772 | $q['nopaging'] = false; |
||
| 1773 | } |
||
| 1774 | } |
||
| 1775 | |||
| 1776 | if ( $this->is_feed ) { |
||
| 1777 | // This overrides posts_per_page. |
||
| 1778 | if ( ! empty( $q['posts_per_rss'] ) ) { |
||
| 1779 | $q['posts_per_page'] = $q['posts_per_rss']; |
||
| 1780 | } else { |
||
| 1781 | $q['posts_per_page'] = get_option( 'posts_per_rss' ); |
||
| 1782 | } |
||
| 1783 | $q['nopaging'] = false; |
||
| 1784 | } |
||
| 1785 | $q['posts_per_page'] = (int) $q['posts_per_page']; |
||
| 1786 | if ( $q['posts_per_page'] < -1 ) |
||
| 1787 | $q['posts_per_page'] = abs($q['posts_per_page']); |
||
| 1788 | elseif ( $q['posts_per_page'] == 0 ) |
||
| 1789 | $q['posts_per_page'] = 1; |
||
| 1790 | |||
| 1791 | if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 ) |
||
| 1792 | $q['comments_per_page'] = get_option('comments_per_page'); |
||
| 1793 | |||
| 1794 | if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) { |
||
| 1795 | $this->is_page = true; |
||
| 1796 | $this->is_home = false; |
||
| 1797 | $q['page_id'] = get_option('page_on_front'); |
||
| 1798 | } |
||
| 1799 | |||
| 1800 | if ( isset($q['page']) ) { |
||
| 1801 | $q['page'] = trim($q['page'], '/'); |
||
| 1802 | $q['page'] = absint($q['page']); |
||
| 1803 | } |
||
| 1804 | |||
| 1805 | // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. |
||
| 1806 | if ( isset($q['no_found_rows']) ) |
||
| 1807 | $q['no_found_rows'] = (bool) $q['no_found_rows']; |
||
| 1808 | else |
||
| 1809 | $q['no_found_rows'] = false; |
||
| 1810 | |||
| 1811 | switch ( $q['fields'] ) { |
||
| 1812 | case 'ids': |
||
| 1813 | $fields = "{$wpdb->posts}.ID"; |
||
| 1814 | break; |
||
| 1815 | case 'id=>parent': |
||
| 1816 | $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent"; |
||
| 1817 | break; |
||
| 1818 | default: |
||
| 1819 | $fields = "{$wpdb->posts}.*"; |
||
| 1820 | } |
||
| 1821 | |||
| 1822 | if ( '' !== $q['menu_order'] ) { |
||
| 1823 | $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order']; |
||
| 1824 | } |
||
| 1825 | // The "m" parameter is meant for months but accepts datetimes of varying specificity |
||
| 1826 | if ( $q['m'] ) { |
||
| 1827 | $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr($q['m'], 0, 4); |
||
| 1828 | View Code Duplication | if ( strlen($q['m']) > 5 ) { |
|
| 1829 | $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 4, 2); |
||
| 1830 | } |
||
| 1831 | View Code Duplication | if ( strlen($q['m']) > 7 ) { |
|
| 1832 | $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 6, 2); |
||
| 1833 | } |
||
| 1834 | View Code Duplication | if ( strlen($q['m']) > 9 ) { |
|
| 1835 | $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr($q['m'], 8, 2); |
||
| 1836 | } |
||
| 1837 | View Code Duplication | if ( strlen($q['m']) > 11 ) { |
|
| 1838 | $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr($q['m'], 10, 2); |
||
| 1839 | } |
||
| 1840 | View Code Duplication | if ( strlen($q['m']) > 13 ) { |
|
| 1841 | $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr($q['m'], 12, 2); |
||
| 1842 | } |
||
| 1843 | } |
||
| 1844 | |||
| 1845 | // Handle the other individual date parameters |
||
| 1846 | $date_parameters = array(); |
||
| 1847 | |||
| 1848 | if ( '' !== $q['hour'] ) |
||
| 1849 | $date_parameters['hour'] = $q['hour']; |
||
| 1850 | |||
| 1851 | if ( '' !== $q['minute'] ) |
||
| 1852 | $date_parameters['minute'] = $q['minute']; |
||
| 1853 | |||
| 1854 | if ( '' !== $q['second'] ) |
||
| 1855 | $date_parameters['second'] = $q['second']; |
||
| 1856 | |||
| 1857 | if ( $q['year'] ) |
||
| 1858 | $date_parameters['year'] = $q['year']; |
||
| 1859 | |||
| 1860 | if ( $q['monthnum'] ) |
||
| 1861 | $date_parameters['monthnum'] = $q['monthnum']; |
||
| 1862 | |||
| 1863 | if ( $q['w'] ) |
||
| 1864 | $date_parameters['week'] = $q['w']; |
||
| 1865 | |||
| 1866 | if ( $q['day'] ) |
||
| 1867 | $date_parameters['day'] = $q['day']; |
||
| 1868 | |||
| 1869 | if ( $date_parameters ) { |
||
| 1870 | $date_query = new WP_Date_Query( array( $date_parameters ) ); |
||
| 1871 | $where .= $date_query->get_sql(); |
||
| 1872 | } |
||
| 1873 | unset( $date_parameters, $date_query ); |
||
| 1874 | |||
| 1875 | // Handle complex date queries |
||
| 1876 | if ( ! empty( $q['date_query'] ) ) { |
||
| 1877 | $this->date_query = new WP_Date_Query( $q['date_query'] ); |
||
| 1878 | $where .= $this->date_query->get_sql(); |
||
| 1879 | } |
||
| 1880 | |||
| 1881 | |||
| 1882 | // If we've got a post_type AND it's not "any" post_type. |
||
| 1883 | if ( !empty($q['post_type']) && 'any' != $q['post_type'] ) { |
||
| 1884 | foreach ( (array)$q['post_type'] as $_post_type ) { |
||
| 1885 | $ptype_obj = get_post_type_object($_post_type); |
||
| 1886 | if ( !$ptype_obj || !$ptype_obj->query_var || empty($q[ $ptype_obj->query_var ]) ) |
||
| 1887 | continue; |
||
| 1888 | |||
| 1889 | if ( ! $ptype_obj->hierarchical ) { |
||
| 1890 | // Non-hierarchical post types can directly use 'name'. |
||
| 1891 | $q['name'] = $q[ $ptype_obj->query_var ]; |
||
| 1892 | } else { |
||
| 1893 | // Hierarchical post types will operate through 'pagename'. |
||
| 1894 | $q['pagename'] = $q[ $ptype_obj->query_var ]; |
||
| 1895 | $q['name'] = ''; |
||
| 1896 | } |
||
| 1897 | |||
| 1898 | // Only one request for a slug is possible, this is why name & pagename are overwritten above. |
||
| 1899 | break; |
||
| 1900 | } //end foreach |
||
| 1901 | unset($ptype_obj); |
||
| 1902 | } |
||
| 1903 | |||
| 1904 | if ( '' !== $q['title'] ) { |
||
| 1905 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q['title'] ) ); |
||
| 1906 | } |
||
| 1907 | |||
| 1908 | // Parameters related to 'post_name'. |
||
| 1909 | if ( '' != $q['name'] ) { |
||
| 1910 | $q['name'] = sanitize_title_for_query( $q['name'] ); |
||
| 1911 | $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'"; |
||
| 1912 | } elseif ( '' != $q['pagename'] ) { |
||
| 1913 | if ( isset($this->queried_object_id) ) { |
||
| 1914 | $reqpage = $this->queried_object_id; |
||
| 1915 | } else { |
||
| 1916 | if ( 'page' != $q['post_type'] ) { |
||
| 1917 | foreach ( (array)$q['post_type'] as $_post_type ) { |
||
| 1918 | $ptype_obj = get_post_type_object($_post_type); |
||
| 1919 | if ( !$ptype_obj || !$ptype_obj->hierarchical ) |
||
| 1920 | continue; |
||
| 1921 | |||
| 1922 | $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type); |
||
| 1923 | if ( $reqpage ) |
||
| 1924 | break; |
||
| 1925 | } |
||
| 1926 | unset($ptype_obj); |
||
| 1927 | } else { |
||
| 1928 | $reqpage = get_page_by_path($q['pagename']); |
||
| 1929 | } |
||
| 1930 | if ( !empty($reqpage) ) |
||
| 1931 | $reqpage = $reqpage->ID; |
||
| 1932 | else |
||
| 1933 | $reqpage = 0; |
||
| 1934 | } |
||
| 1935 | |||
| 1936 | $page_for_posts = get_option('page_for_posts'); |
||
| 1937 | if ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) { |
||
| 1938 | $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); |
||
| 1939 | $q['name'] = $q['pagename']; |
||
| 1940 | $where .= " AND ({$wpdb->posts}.ID = '$reqpage')"; |
||
| 1941 | $reqpage_obj = get_post( $reqpage ); |
||
| 1942 | if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { |
||
| 1943 | $this->is_attachment = true; |
||
| 1944 | $post_type = $q['post_type'] = 'attachment'; |
||
| 1945 | $this->is_page = true; |
||
| 1946 | $q['attachment_id'] = $reqpage; |
||
| 1947 | } |
||
| 1948 | } |
||
| 1949 | } elseif ( '' != $q['attachment'] ) { |
||
| 1950 | $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); |
||
| 1951 | $q['name'] = $q['attachment']; |
||
| 1952 | $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'"; |
||
| 1953 | } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { |
||
| 1954 | $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); |
||
| 1955 | $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'"; |
||
| 1956 | $where .= " AND {$wpdb->posts}.post_name IN ($post_name__in)"; |
||
| 1957 | } |
||
| 1958 | |||
| 1959 | // If an attachment is requested by number, let it supersede any post number. |
||
| 1960 | if ( $q['attachment_id'] ) |
||
| 1961 | $q['p'] = absint($q['attachment_id']); |
||
| 1962 | |||
| 1963 | // If a post number is specified, load that post |
||
| 1964 | View Code Duplication | if ( $q['p'] ) { |
|
| 1965 | $where .= " AND {$wpdb->posts}.ID = " . $q['p']; |
||
| 1966 | } elseif ( $q['post__in'] ) { |
||
| 1967 | $post__in = implode(',', array_map( 'absint', $q['post__in'] )); |
||
| 1968 | $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; |
||
| 1969 | } elseif ( $q['post__not_in'] ) { |
||
| 1970 | $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] )); |
||
| 1971 | $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; |
||
| 1972 | } |
||
| 1973 | |||
| 1974 | View Code Duplication | if ( is_numeric( $q['post_parent'] ) ) { |
|
| 1975 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $q['post_parent'] ); |
||
| 1976 | } elseif ( $q['post_parent__in'] ) { |
||
| 1977 | $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); |
||
| 1978 | $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; |
||
| 1979 | } elseif ( $q['post_parent__not_in'] ) { |
||
| 1980 | $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); |
||
| 1981 | $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; |
||
| 1982 | } |
||
| 1983 | |||
| 1984 | if ( $q['page_id'] ) { |
||
| 1985 | if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) { |
||
| 1986 | $q['p'] = $q['page_id']; |
||
| 1987 | $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; |
||
| 1988 | } |
||
| 1989 | } |
||
| 1990 | |||
| 1991 | // If a search pattern is specified, load the posts that match. |
||
| 1992 | if ( strlen( $q['s'] ) ) { |
||
| 1993 | $search = $this->parse_search( $q ); |
||
| 1994 | } |
||
| 1995 | |||
| 1996 | if ( ! $q['suppress_filters'] ) { |
||
| 1997 | /** |
||
| 1998 | * Filters the search SQL that is used in the WHERE clause of WP_Query. |
||
| 1999 | * |
||
| 2000 | * @since 3.0.0 |
||
| 2001 | * |
||
| 2002 | * @param string $search Search SQL for WHERE clause. |
||
| 2003 | * @param WP_Query $this The current WP_Query object. |
||
| 2004 | */ |
||
| 2005 | $search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) ); |
||
| 2006 | } |
||
| 2007 | |||
| 2008 | // Taxonomies |
||
| 2009 | if ( !$this->is_singular ) { |
||
| 2010 | $this->parse_tax_query( $q ); |
||
| 2011 | |||
| 2012 | $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); |
||
| 2013 | |||
| 2014 | $join .= $clauses['join']; |
||
| 2015 | $where .= $clauses['where']; |
||
| 2016 | } |
||
| 2017 | |||
| 2018 | if ( $this->is_tax ) { |
||
| 2019 | if ( empty($post_type) ) { |
||
| 2020 | // Do a fully inclusive search for currently registered post types of queried taxonomies |
||
| 2021 | $post_type = array(); |
||
| 2022 | $taxonomies = array_keys( $this->tax_query->queried_terms ); |
||
| 2023 | foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { |
||
| 2024 | $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); |
||
| 2025 | if ( array_intersect( $taxonomies, $object_taxonomies ) ) |
||
| 2026 | $post_type[] = $pt; |
||
| 2027 | } |
||
| 2028 | if ( ! $post_type ) |
||
| 2029 | $post_type = 'any'; |
||
| 2030 | elseif ( count( $post_type ) == 1 ) |
||
| 2031 | $post_type = $post_type[0]; |
||
| 2032 | |||
| 2033 | $post_status_join = true; |
||
| 2034 | } elseif ( in_array('attachment', (array) $post_type) ) { |
||
| 2035 | $post_status_join = true; |
||
| 2036 | } |
||
| 2037 | } |
||
| 2038 | |||
| 2039 | /* |
||
| 2040 | * Ensure that 'taxonomy', 'term', 'term_id', 'cat', and |
||
| 2041 | * 'category_name' vars are set for backward compatibility. |
||
| 2042 | */ |
||
| 2043 | if ( ! empty( $this->tax_query->queried_terms ) ) { |
||
| 2044 | |||
| 2045 | /* |
||
| 2046 | * Set 'taxonomy', 'term', and 'term_id' to the |
||
| 2047 | * first taxonomy other than 'post_tag' or 'category'. |
||
| 2048 | */ |
||
| 2049 | if ( ! isset( $q['taxonomy'] ) ) { |
||
| 2050 | foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { |
||
| 2051 | if ( empty( $queried_items['terms'][0] ) ) { |
||
| 2052 | continue; |
||
| 2053 | } |
||
| 2054 | |||
| 2055 | if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ) ) ) { |
||
| 2056 | $q['taxonomy'] = $queried_taxonomy; |
||
| 2057 | |||
| 2058 | if ( 'slug' === $queried_items['field'] ) { |
||
| 2059 | $q['term'] = $queried_items['terms'][0]; |
||
| 2060 | } else { |
||
| 2061 | $q['term_id'] = $queried_items['terms'][0]; |
||
| 2062 | } |
||
| 2063 | |||
| 2064 | // Take the first one we find. |
||
| 2065 | break; |
||
| 2066 | } |
||
| 2067 | } |
||
| 2068 | } |
||
| 2069 | |||
| 2070 | // 'cat', 'category_name', 'tag_id' |
||
| 2071 | foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { |
||
| 2072 | if ( empty( $queried_items['terms'][0] ) ) { |
||
| 2073 | continue; |
||
| 2074 | } |
||
| 2075 | |||
| 2076 | View Code Duplication | if ( 'category' === $queried_taxonomy ) { |
|
| 2077 | $the_cat = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'category' ); |
||
| 2078 | if ( $the_cat ) { |
||
| 2079 | $this->set( 'cat', $the_cat->term_id ); |
||
| 2080 | $this->set( 'category_name', $the_cat->slug ); |
||
| 2081 | } |
||
| 2082 | unset( $the_cat ); |
||
| 2083 | } |
||
| 2084 | |||
| 2085 | View Code Duplication | if ( 'post_tag' === $queried_taxonomy ) { |
|
| 2086 | $the_tag = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'post_tag' ); |
||
| 2087 | if ( $the_tag ) { |
||
| 2088 | $this->set( 'tag_id', $the_tag->term_id ); |
||
| 2089 | } |
||
| 2090 | unset( $the_tag ); |
||
| 2091 | } |
||
| 2092 | } |
||
| 2093 | } |
||
| 2094 | |||
| 2095 | if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { |
||
| 2096 | $groupby = "{$wpdb->posts}.ID"; |
||
| 2097 | } |
||
| 2098 | |||
| 2099 | // Author/user stuff |
||
| 2100 | |||
| 2101 | if ( ! empty( $q['author'] ) && $q['author'] != '0' ) { |
||
| 2102 | $q['author'] = addslashes_gpc( '' . urldecode( $q['author'] ) ); |
||
| 2103 | $authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $q['author'] ) ) ); |
||
| 2104 | foreach ( $authors as $author ) { |
||
| 2105 | $key = $author > 0 ? 'author__in' : 'author__not_in'; |
||
| 2106 | $q[$key][] = abs( $author ); |
||
| 2107 | } |
||
| 2108 | $q['author'] = implode( ',', $authors ); |
||
| 2109 | } |
||
| 2110 | |||
| 2111 | if ( ! empty( $q['author__not_in'] ) ) { |
||
| 2112 | $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) ); |
||
| 2113 | $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) "; |
||
| 2114 | } elseif ( ! empty( $q['author__in'] ) ) { |
||
| 2115 | $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) ); |
||
| 2116 | $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; |
||
| 2117 | } |
||
| 2118 | |||
| 2119 | // Author stuff for nice URLs |
||
| 2120 | |||
| 2121 | if ( '' != $q['author_name'] ) { |
||
| 2122 | if ( strpos($q['author_name'], '/') !== false ) { |
||
| 2123 | $q['author_name'] = explode('/', $q['author_name']); |
||
| 2124 | if ( $q['author_name'][ count($q['author_name'])-1 ] ) { |
||
| 2125 | $q['author_name'] = $q['author_name'][count($q['author_name'])-1]; // no trailing slash |
||
| 2126 | } else { |
||
| 2127 | $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailing slash |
||
| 2128 | } |
||
| 2129 | } |
||
| 2130 | $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); |
||
| 2131 | $q['author'] = get_user_by('slug', $q['author_name']); |
||
| 2132 | if ( $q['author'] ) |
||
| 2133 | $q['author'] = $q['author']->ID; |
||
| 2134 | $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint($q['author']) . ')'; |
||
| 2135 | } |
||
| 2136 | |||
| 2137 | // MIME-Type stuff for attachment browsing |
||
| 2138 | |||
| 2139 | if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { |
||
| 2140 | $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); |
||
| 2141 | } |
||
| 2142 | $where .= $search . $whichauthor . $whichmimetype; |
||
| 2143 | |||
| 2144 | if ( ! empty( $this->meta_query->queries ) ) { |
||
| 2145 | $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this ); |
||
| 2146 | $join .= $clauses['join']; |
||
| 2147 | $where .= $clauses['where']; |
||
| 2148 | } |
||
| 2149 | |||
| 2150 | $rand = ( isset( $q['orderby'] ) && 'rand' === $q['orderby'] ); |
||
| 2151 | if ( ! isset( $q['order'] ) ) { |
||
| 2152 | $q['order'] = $rand ? '' : 'DESC'; |
||
| 2153 | } else { |
||
| 2154 | $q['order'] = $rand ? '' : $this->parse_order( $q['order'] ); |
||
| 2155 | } |
||
| 2156 | |||
| 2157 | // Order by. |
||
| 2158 | if ( empty( $q['orderby'] ) ) { |
||
| 2159 | /* |
||
| 2160 | * Boolean false or empty array blanks out ORDER BY, |
||
| 2161 | * while leaving the value unset or otherwise empty sets the default. |
||
| 2162 | */ |
||
| 2163 | if ( isset( $q['orderby'] ) && ( is_array( $q['orderby'] ) || false === $q['orderby'] ) ) { |
||
| 2164 | $orderby = ''; |
||
| 2165 | } else { |
||
| 2166 | $orderby = "{$wpdb->posts}.post_date " . $q['order']; |
||
| 2167 | } |
||
| 2168 | } elseif ( 'none' == $q['orderby'] ) { |
||
| 2169 | $orderby = ''; |
||
| 2170 | } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { |
||
| 2171 | $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; |
||
| 2172 | } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { |
||
| 2173 | $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; |
||
| 2174 | } elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) { |
||
| 2175 | $orderby = "FIELD( {$wpdb->posts}.post_name, $post_name__in )"; |
||
| 2176 | } else { |
||
| 2177 | $orderby_array = array(); |
||
| 2178 | if ( is_array( $q['orderby'] ) ) { |
||
| 2179 | foreach ( $q['orderby'] as $_orderby => $order ) { |
||
| 2180 | $orderby = addslashes_gpc( urldecode( $_orderby ) ); |
||
| 2181 | $parsed = $this->parse_orderby( $orderby ); |
||
| 2182 | |||
| 2183 | if ( ! $parsed ) { |
||
| 2184 | continue; |
||
| 2185 | } |
||
| 2186 | |||
| 2187 | $orderby_array[] = $parsed . ' ' . $this->parse_order( $order ); |
||
| 2188 | } |
||
| 2189 | $orderby = implode( ', ', $orderby_array ); |
||
| 2190 | |||
| 2191 | } else { |
||
| 2192 | $q['orderby'] = urldecode( $q['orderby'] ); |
||
| 2193 | $q['orderby'] = addslashes_gpc( $q['orderby'] ); |
||
| 2194 | |||
| 2195 | foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) { |
||
| 2196 | $parsed = $this->parse_orderby( $orderby ); |
||
| 2197 | // Only allow certain values for safety. |
||
| 2198 | if ( ! $parsed ) { |
||
| 2199 | continue; |
||
| 2200 | } |
||
| 2201 | |||
| 2202 | $orderby_array[] = $parsed; |
||
| 2203 | } |
||
| 2204 | $orderby = implode( ' ' . $q['order'] . ', ', $orderby_array ); |
||
| 2205 | |||
| 2206 | if ( empty( $orderby ) ) { |
||
| 2207 | $orderby = "{$wpdb->posts}.post_date " . $q['order']; |
||
| 2208 | } elseif ( ! empty( $q['order'] ) ) { |
||
| 2209 | $orderby .= " {$q['order']}"; |
||
| 2210 | } |
||
| 2211 | } |
||
| 2212 | } |
||
| 2213 | |||
| 2214 | // Order search results by relevance only when another "orderby" is not specified in the query. |
||
| 2215 | if ( ! empty( $q['s'] ) ) { |
||
| 2216 | $search_orderby = ''; |
||
| 2217 | if ( ! empty( $q['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) ) |
||
| 2218 | $search_orderby = $this->parse_search_order( $q ); |
||
| 2219 | |||
| 2220 | if ( ! $q['suppress_filters'] ) { |
||
| 2221 | /** |
||
| 2222 | * Filters the ORDER BY used when ordering search results. |
||
| 2223 | * |
||
| 2224 | * @since 3.7.0 |
||
| 2225 | * |
||
| 2226 | * @param string $search_orderby The ORDER BY clause. |
||
| 2227 | * @param WP_Query $this The current WP_Query instance. |
||
| 2228 | */ |
||
| 2229 | $search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this ); |
||
| 2230 | } |
||
| 2231 | |||
| 2232 | if ( $search_orderby ) |
||
| 2233 | $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby; |
||
| 2234 | } |
||
| 2235 | |||
| 2236 | if ( is_array( $post_type ) && count( $post_type ) > 1 ) { |
||
| 2237 | $post_type_cap = 'multiple_post_type'; |
||
| 2238 | } else { |
||
| 2239 | if ( is_array( $post_type ) ) |
||
| 2240 | $post_type = reset( $post_type ); |
||
| 2241 | $post_type_object = get_post_type_object( $post_type ); |
||
| 2242 | if ( empty( $post_type_object ) ) |
||
| 2243 | $post_type_cap = $post_type; |
||
| 2244 | } |
||
| 2245 | |||
| 2246 | if ( isset( $q['post_password'] ) ) { |
||
| 2247 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q['post_password'] ); |
||
| 2248 | if ( empty( $q['perm'] ) ) { |
||
| 2249 | $q['perm'] = 'readable'; |
||
| 2250 | } |
||
| 2251 | } elseif ( isset( $q['has_password'] ) ) { |
||
| 2252 | $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' ); |
||
| 2253 | } |
||
| 2254 | |||
| 2255 | View Code Duplication | if ( ! empty( $q['comment_status'] ) ) { |
|
| 2256 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q['comment_status'] ); |
||
| 2257 | } |
||
| 2258 | |||
| 2259 | View Code Duplication | if ( ! empty( $q['ping_status'] ) ) { |
|
| 2260 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] ); |
||
| 2261 | } |
||
| 2262 | |||
| 2263 | if ( 'any' == $post_type ) { |
||
| 2264 | $in_search_post_types = get_post_types( array('exclude_from_search' => false) ); |
||
| 2265 | if ( empty( $in_search_post_types ) ) { |
||
| 2266 | $where .= ' AND 1=0 '; |
||
| 2267 | } else { |
||
| 2268 | $where .= " AND {$wpdb->posts}.post_type IN ('" . join( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')"; |
||
| 2269 | } |
||
| 2270 | } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { |
||
| 2271 | $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", esc_sql( $post_type ) ) . "')"; |
||
| 2272 | } elseif ( ! empty( $post_type ) ) { |
||
| 2273 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type ); |
||
| 2274 | $post_type_object = get_post_type_object ( $post_type ); |
||
| 2275 | } elseif ( $this->is_attachment ) { |
||
| 2276 | $where .= " AND {$wpdb->posts}.post_type = 'attachment'"; |
||
| 2277 | $post_type_object = get_post_type_object ( 'attachment' ); |
||
| 2278 | } elseif ( $this->is_page ) { |
||
| 2279 | $where .= " AND {$wpdb->posts}.post_type = 'page'"; |
||
| 2280 | $post_type_object = get_post_type_object ( 'page' ); |
||
| 2281 | } else { |
||
| 2282 | $where .= " AND {$wpdb->posts}.post_type = 'post'"; |
||
| 2283 | $post_type_object = get_post_type_object ( 'post' ); |
||
| 2284 | } |
||
| 2285 | |||
| 2286 | $edit_cap = 'edit_post'; |
||
| 2287 | $read_cap = 'read_post'; |
||
| 2288 | |||
| 2289 | if ( ! empty( $post_type_object ) ) { |
||
| 2290 | $edit_others_cap = $post_type_object->cap->edit_others_posts; |
||
| 2291 | $read_private_cap = $post_type_object->cap->read_private_posts; |
||
| 2292 | } else { |
||
| 2293 | $edit_others_cap = 'edit_others_' . $post_type_cap . 's'; |
||
| 2294 | $read_private_cap = 'read_private_' . $post_type_cap . 's'; |
||
| 2295 | } |
||
| 2296 | |||
| 2297 | $user_id = get_current_user_id(); |
||
| 2298 | |||
| 2299 | $q_status = array(); |
||
| 2300 | if ( ! empty( $q['post_status'] ) ) { |
||
| 2301 | $statuswheres = array(); |
||
| 2302 | $q_status = $q['post_status']; |
||
| 2303 | if ( ! is_array( $q_status ) ) |
||
| 2304 | $q_status = explode(',', $q_status); |
||
| 2305 | $r_status = array(); |
||
| 2306 | $p_status = array(); |
||
| 2307 | $e_status = array(); |
||
| 2308 | if ( in_array( 'any', $q_status ) ) { |
||
| 2309 | foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { |
||
| 2310 | if ( ! in_array( $status, $q_status ) ) { |
||
| 2311 | $e_status[] = "{$wpdb->posts}.post_status <> '$status'"; |
||
| 2312 | } |
||
| 2313 | } |
||
| 2314 | } else { |
||
| 2315 | foreach ( get_post_stati() as $status ) { |
||
| 2316 | if ( in_array( $status, $q_status ) ) { |
||
| 2317 | if ( 'private' == $status ) { |
||
| 2318 | $p_status[] = "{$wpdb->posts}.post_status = '$status'"; |
||
| 2319 | } else { |
||
| 2320 | $r_status[] = "{$wpdb->posts}.post_status = '$status'"; |
||
| 2321 | } |
||
| 2322 | } |
||
| 2323 | } |
||
| 2324 | } |
||
| 2325 | |||
| 2326 | if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) { |
||
| 2327 | $r_status = array_merge($r_status, $p_status); |
||
| 2328 | unset($p_status); |
||
| 2329 | } |
||
| 2330 | |||
| 2331 | if ( !empty($e_status) ) { |
||
| 2332 | $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")"; |
||
| 2333 | } |
||
| 2334 | View Code Duplication | if ( !empty($r_status) ) { |
|
| 2335 | if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) { |
||
| 2336 | $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; |
||
| 2337 | } else { |
||
| 2338 | $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; |
||
| 2339 | } |
||
| 2340 | } |
||
| 2341 | View Code Duplication | if ( !empty($p_status) ) { |
|
| 2342 | if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) { |
||
| 2343 | $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; |
||
| 2344 | } else { |
||
| 2345 | $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; |
||
| 2346 | } |
||
| 2347 | } |
||
| 2348 | if ( $post_status_join ) { |
||
| 2349 | $join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) "; |
||
| 2350 | foreach ( $statuswheres as $index => $statuswhere ) { |
||
| 2351 | $statuswheres[$index] = "($statuswhere OR ({$wpdb->posts}.post_status = 'inherit' AND " . str_replace( $wpdb->posts, 'p2', $statuswhere ) . "))"; |
||
| 2352 | } |
||
| 2353 | } |
||
| 2354 | $where_status = implode( ' OR ', $statuswheres ); |
||
| 2355 | if ( ! empty( $where_status ) ) { |
||
| 2356 | $where .= " AND ($where_status)"; |
||
| 2357 | } |
||
| 2358 | } elseif ( !$this->is_singular ) { |
||
| 2359 | $where .= " AND ({$wpdb->posts}.post_status = 'publish'"; |
||
| 2360 | |||
| 2361 | // Add public states. |
||
| 2362 | $public_states = get_post_stati( array('public' => true) ); |
||
| 2363 | foreach ( (array) $public_states as $state ) { |
||
| 2364 | if ( 'publish' == $state ) // Publish is hard-coded above. |
||
| 2365 | continue; |
||
| 2366 | $where .= " OR {$wpdb->posts}.post_status = '$state'"; |
||
| 2367 | } |
||
| 2368 | |||
| 2369 | if ( $this->is_admin ) { |
||
| 2370 | // Add protected states that should show in the admin all list. |
||
| 2371 | $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); |
||
| 2372 | foreach ( (array) $admin_all_states as $state ) { |
||
| 2373 | $where .= " OR {$wpdb->posts}.post_status = '$state'"; |
||
| 2374 | } |
||
| 2375 | } |
||
| 2376 | |||
| 2377 | if ( is_user_logged_in() ) { |
||
| 2378 | // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. |
||
| 2379 | $private_states = get_post_stati( array('private' => true) ); |
||
| 2380 | foreach ( (array) $private_states as $state ) { |
||
| 2381 | $where .= current_user_can( $read_private_cap ) ? " OR {$wpdb->posts}.post_status = '$state'" : " OR {$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$state'"; |
||
| 2382 | } |
||
| 2383 | } |
||
| 2384 | |||
| 2385 | $where .= ')'; |
||
| 2386 | } |
||
| 2387 | |||
| 2388 | /* |
||
| 2389 | * Apply filters on where and join prior to paging so that any |
||
| 2390 | * manipulations to them are reflected in the paging by day queries. |
||
| 2391 | */ |
||
| 2392 | if ( !$q['suppress_filters'] ) { |
||
| 2393 | /** |
||
| 2394 | * Filters the WHERE clause of the query. |
||
| 2395 | * |
||
| 2396 | * @since 1.5.0 |
||
| 2397 | * |
||
| 2398 | * @param string $where The WHERE clause of the query. |
||
| 2399 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2400 | */ |
||
| 2401 | $where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) ); |
||
| 2402 | |||
| 2403 | /** |
||
| 2404 | * Filters the JOIN clause of the query. |
||
| 2405 | * |
||
| 2406 | * @since 1.5.0 |
||
| 2407 | * |
||
| 2408 | * @param string $join The JOIN clause of the query. |
||
| 2409 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2410 | */ |
||
| 2411 | $join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) ); |
||
| 2412 | } |
||
| 2413 | |||
| 2414 | // Paging |
||
| 2415 | if ( empty($q['nopaging']) && !$this->is_singular ) { |
||
| 2416 | $page = absint($q['paged']); |
||
| 2417 | if ( !$page ) |
||
| 2418 | $page = 1; |
||
| 2419 | |||
| 2420 | // If 'offset' is provided, it takes precedence over 'paged'. |
||
| 2421 | if ( isset( $q['offset'] ) && is_numeric( $q['offset'] ) ) { |
||
| 2422 | $q['offset'] = absint( $q['offset'] ); |
||
| 2423 | $pgstrt = $q['offset'] . ', '; |
||
| 2424 | } else { |
||
| 2425 | $pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', '; |
||
| 2426 | } |
||
| 2427 | $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; |
||
| 2428 | } |
||
| 2429 | |||
| 2430 | // Comments feeds |
||
| 2431 | if ( $this->is_comment_feed && ! $this->is_singular ) { |
||
| 2432 | if ( $this->is_archive || $this->is_search ) { |
||
| 2433 | $cjoin = "JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) $join "; |
||
| 2434 | $cwhere = "WHERE comment_approved = '1' $where"; |
||
| 2435 | $cgroupby = "{$wpdb->comments}.comment_id"; |
||
| 2436 | } else { // Other non singular e.g. front |
||
| 2437 | $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )"; |
||
| 2438 | $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'"; |
||
| 2439 | $cgroupby = ''; |
||
| 2440 | } |
||
| 2441 | |||
| 2442 | if ( !$q['suppress_filters'] ) { |
||
| 2443 | /** |
||
| 2444 | * Filters the JOIN clause of the comments feed query before sending. |
||
| 2445 | * |
||
| 2446 | * @since 2.2.0 |
||
| 2447 | * |
||
| 2448 | * @param string $cjoin The JOIN clause of the query. |
||
| 2449 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2450 | */ |
||
| 2451 | $cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) ); |
||
| 2452 | |||
| 2453 | /** |
||
| 2454 | * Filters the WHERE clause of the comments feed query before sending. |
||
| 2455 | * |
||
| 2456 | * @since 2.2.0 |
||
| 2457 | * |
||
| 2458 | * @param string $cwhere The WHERE clause of the query. |
||
| 2459 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2460 | */ |
||
| 2461 | $cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) ); |
||
| 2462 | |||
| 2463 | /** |
||
| 2464 | * Filters the GROUP BY clause of the comments feed query before sending. |
||
| 2465 | * |
||
| 2466 | * @since 2.2.0 |
||
| 2467 | * |
||
| 2468 | * @param string $cgroupby The GROUP BY clause of the query. |
||
| 2469 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2470 | */ |
||
| 2471 | $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) ); |
||
| 2472 | |||
| 2473 | /** |
||
| 2474 | * Filters the ORDER BY clause of the comments feed query before sending. |
||
| 2475 | * |
||
| 2476 | * @since 2.8.0 |
||
| 2477 | * |
||
| 2478 | * @param string $corderby The ORDER BY clause of the query. |
||
| 2479 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2480 | */ |
||
| 2481 | $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); |
||
| 2482 | |||
| 2483 | /** |
||
| 2484 | * Filters the LIMIT clause of the comments feed query before sending. |
||
| 2485 | * |
||
| 2486 | * @since 2.8.0 |
||
| 2487 | * |
||
| 2488 | * @param string $climits The JOIN clause of the query. |
||
| 2489 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2490 | */ |
||
| 2491 | $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); |
||
| 2492 | } |
||
| 2493 | $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; |
||
| 2494 | $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; |
||
| 2495 | |||
| 2496 | $comments = (array) $wpdb->get_results("SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"); |
||
| 2497 | // Convert to WP_Comment |
||
| 2498 | $this->comments = array_map( 'get_comment', $comments ); |
||
| 2499 | $this->comment_count = count($this->comments); |
||
| 2500 | |||
| 2501 | $post_ids = array(); |
||
| 2502 | |||
| 2503 | foreach ( $this->comments as $comment ) |
||
| 2504 | $post_ids[] = (int) $comment->comment_post_ID; |
||
| 2505 | |||
| 2506 | $post_ids = join(',', $post_ids); |
||
| 2507 | $join = ''; |
||
| 2508 | if ( $post_ids ) { |
||
| 2509 | $where = "AND {$wpdb->posts}.ID IN ($post_ids) "; |
||
| 2510 | } else { |
||
| 2511 | $where = "AND 0"; |
||
| 2512 | } |
||
| 2513 | } |
||
| 2514 | |||
| 2515 | $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); |
||
| 2516 | |||
| 2517 | /* |
||
| 2518 | * Apply post-paging filters on where and join. Only plugins that |
||
| 2519 | * manipulate paging queries should use these hooks. |
||
| 2520 | */ |
||
| 2521 | View Code Duplication | if ( !$q['suppress_filters'] ) { |
|
| 2522 | /** |
||
| 2523 | * Filters the WHERE clause of the query. |
||
| 2524 | * |
||
| 2525 | * Specifically for manipulating paging queries. |
||
| 2526 | * |
||
| 2527 | * @since 1.5.0 |
||
| 2528 | * |
||
| 2529 | * @param string $where The WHERE clause of the query. |
||
| 2530 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2531 | */ |
||
| 2532 | $where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) ); |
||
| 2533 | |||
| 2534 | /** |
||
| 2535 | * Filters the GROUP BY clause of the query. |
||
| 2536 | * |
||
| 2537 | * @since 2.0.0 |
||
| 2538 | * |
||
| 2539 | * @param string $groupby The GROUP BY clause of the query. |
||
| 2540 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2541 | */ |
||
| 2542 | $groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) ); |
||
| 2543 | |||
| 2544 | /** |
||
| 2545 | * Filters the JOIN clause of the query. |
||
| 2546 | * |
||
| 2547 | * Specifically for manipulating paging queries. |
||
| 2548 | * |
||
| 2549 | * @since 1.5.0 |
||
| 2550 | * |
||
| 2551 | * @param string $join The JOIN clause of the query. |
||
| 2552 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2553 | */ |
||
| 2554 | $join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) ); |
||
| 2555 | |||
| 2556 | /** |
||
| 2557 | * Filters the ORDER BY clause of the query. |
||
| 2558 | * |
||
| 2559 | * @since 1.5.1 |
||
| 2560 | * |
||
| 2561 | * @param string $orderby The ORDER BY clause of the query. |
||
| 2562 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2563 | */ |
||
| 2564 | $orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) ); |
||
| 2565 | |||
| 2566 | /** |
||
| 2567 | * Filters the DISTINCT clause of the query. |
||
| 2568 | * |
||
| 2569 | * @since 2.1.0 |
||
| 2570 | * |
||
| 2571 | * @param string $distinct The DISTINCT clause of the query. |
||
| 2572 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2573 | */ |
||
| 2574 | $distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) ); |
||
| 2575 | |||
| 2576 | /** |
||
| 2577 | * Filters the LIMIT clause of the query. |
||
| 2578 | * |
||
| 2579 | * @since 2.1.0 |
||
| 2580 | * |
||
| 2581 | * @param string $limits The LIMIT clause of the query. |
||
| 2582 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2583 | */ |
||
| 2584 | $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) ); |
||
| 2585 | |||
| 2586 | /** |
||
| 2587 | * Filters the SELECT clause of the query. |
||
| 2588 | * |
||
| 2589 | * @since 2.1.0 |
||
| 2590 | * |
||
| 2591 | * @param string $fields The SELECT clause of the query. |
||
| 2592 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2593 | */ |
||
| 2594 | $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) ); |
||
| 2595 | |||
| 2596 | /** |
||
| 2597 | * Filters all query clauses at once, for convenience. |
||
| 2598 | * |
||
| 2599 | * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, |
||
| 2600 | * fields (SELECT), and LIMITS clauses. |
||
| 2601 | * |
||
| 2602 | * @since 3.1.0 |
||
| 2603 | * |
||
| 2604 | * @param array $clauses The list of clauses for the query. |
||
| 2605 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2606 | */ |
||
| 2607 | $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) ); |
||
| 2608 | |||
| 2609 | $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
||
| 2610 | $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : ''; |
||
| 2611 | $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
||
| 2612 | $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
||
| 2613 | $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : ''; |
||
| 2614 | $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
||
| 2615 | $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
||
| 2616 | } |
||
| 2617 | |||
| 2618 | /** |
||
| 2619 | * Fires to announce the query's current selection parameters. |
||
| 2620 | * |
||
| 2621 | * For use by caching plugins. |
||
| 2622 | * |
||
| 2623 | * @since 2.3.0 |
||
| 2624 | * |
||
| 2625 | * @param string $selection The assembled selection query. |
||
| 2626 | */ |
||
| 2627 | do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join ); |
||
| 2628 | |||
| 2629 | /* |
||
| 2630 | * Filters again for the benefit of caching plugins. |
||
| 2631 | * Regular plugins should use the hooks above. |
||
| 2632 | */ |
||
| 2633 | View Code Duplication | if ( !$q['suppress_filters'] ) { |
|
| 2634 | /** |
||
| 2635 | * Filters the WHERE clause of the query. |
||
| 2636 | * |
||
| 2637 | * For use by caching plugins. |
||
| 2638 | * |
||
| 2639 | * @since 2.5.0 |
||
| 2640 | * |
||
| 2641 | * @param string $where The WHERE clause of the query. |
||
| 2642 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2643 | */ |
||
| 2644 | $where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) ); |
||
| 2645 | |||
| 2646 | /** |
||
| 2647 | * Filters the GROUP BY clause of the query. |
||
| 2648 | * |
||
| 2649 | * For use by caching plugins. |
||
| 2650 | * |
||
| 2651 | * @since 2.5.0 |
||
| 2652 | * |
||
| 2653 | * @param string $groupby The GROUP BY clause of the query. |
||
| 2654 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2655 | */ |
||
| 2656 | $groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) ); |
||
| 2657 | |||
| 2658 | /** |
||
| 2659 | * Filters the JOIN clause of the query. |
||
| 2660 | * |
||
| 2661 | * For use by caching plugins. |
||
| 2662 | * |
||
| 2663 | * @since 2.5.0 |
||
| 2664 | * |
||
| 2665 | * @param string $join The JOIN clause of the query. |
||
| 2666 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2667 | */ |
||
| 2668 | $join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) ); |
||
| 2669 | |||
| 2670 | /** |
||
| 2671 | * Filters the ORDER BY clause of the query. |
||
| 2672 | * |
||
| 2673 | * For use by caching plugins. |
||
| 2674 | * |
||
| 2675 | * @since 2.5.0 |
||
| 2676 | * |
||
| 2677 | * @param string $orderby The ORDER BY clause of the query. |
||
| 2678 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2679 | */ |
||
| 2680 | $orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) ); |
||
| 2681 | |||
| 2682 | /** |
||
| 2683 | * Filters the DISTINCT clause of the query. |
||
| 2684 | * |
||
| 2685 | * For use by caching plugins. |
||
| 2686 | * |
||
| 2687 | * @since 2.5.0 |
||
| 2688 | * |
||
| 2689 | * @param string $distinct The DISTINCT clause of the query. |
||
| 2690 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2691 | */ |
||
| 2692 | $distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) ); |
||
| 2693 | |||
| 2694 | /** |
||
| 2695 | * Filters the SELECT clause of the query. |
||
| 2696 | * |
||
| 2697 | * For use by caching plugins. |
||
| 2698 | * |
||
| 2699 | * @since 2.5.0 |
||
| 2700 | * |
||
| 2701 | * @param string $fields The SELECT clause of the query. |
||
| 2702 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2703 | */ |
||
| 2704 | $fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) ); |
||
| 2705 | |||
| 2706 | /** |
||
| 2707 | * Filters the LIMIT clause of the query. |
||
| 2708 | * |
||
| 2709 | * For use by caching plugins. |
||
| 2710 | * |
||
| 2711 | * @since 2.5.0 |
||
| 2712 | * |
||
| 2713 | * @param string $limits The LIMIT clause of the query. |
||
| 2714 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2715 | */ |
||
| 2716 | $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) ); |
||
| 2717 | |||
| 2718 | /** |
||
| 2719 | * Filters all query clauses at once, for convenience. |
||
| 2720 | * |
||
| 2721 | * For use by caching plugins. |
||
| 2722 | * |
||
| 2723 | * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, |
||
| 2724 | * fields (SELECT), and LIMITS clauses. |
||
| 2725 | * |
||
| 2726 | * @since 3.1.0 |
||
| 2727 | * |
||
| 2728 | * @param array $pieces The pieces of the query. |
||
| 2729 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2730 | */ |
||
| 2731 | $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) ); |
||
| 2732 | |||
| 2733 | $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
||
| 2734 | $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : ''; |
||
| 2735 | $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
||
| 2736 | $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
||
| 2737 | $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : ''; |
||
| 2738 | $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
||
| 2739 | $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
||
| 2740 | } |
||
| 2741 | |||
| 2742 | if ( ! empty($groupby) ) |
||
| 2743 | $groupby = 'GROUP BY ' . $groupby; |
||
| 2744 | if ( !empty( $orderby ) ) |
||
| 2745 | $orderby = 'ORDER BY ' . $orderby; |
||
| 2746 | |||
| 2747 | $found_rows = ''; |
||
| 2748 | if ( !$q['no_found_rows'] && !empty($limits) ) |
||
| 2749 | $found_rows = 'SQL_CALC_FOUND_ROWS'; |
||
| 2750 | |||
| 2751 | $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; |
||
| 2752 | |||
| 2753 | if ( !$q['suppress_filters'] ) { |
||
| 2754 | /** |
||
| 2755 | * Filters the completed SQL query before sending. |
||
| 2756 | * |
||
| 2757 | * @since 2.0.0 |
||
| 2758 | * |
||
| 2759 | * @param string $request The complete SQL query. |
||
| 2760 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2761 | */ |
||
| 2762 | $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) ); |
||
| 2763 | } |
||
| 2764 | |||
| 2765 | /** |
||
| 2766 | * Filters the posts array before the query takes place. |
||
| 2767 | * |
||
| 2768 | * Return a non-null value to bypass WordPress's default post queries. |
||
| 2769 | * |
||
| 2770 | * Filtering functions that require pagination information are encouraged to set |
||
| 2771 | * the `found_posts` and `max_num_pages` properties of the WP_Query object, |
||
| 2772 | * passed to the filter by reference. If WP_Query does not perform a database |
||
| 2773 | * query, it will not have enough information to generate these values itself. |
||
| 2774 | * |
||
| 2775 | * @since 4.6.0 |
||
| 2776 | * |
||
| 2777 | * @param array|null $posts Return an array of post data to short-circuit WP's query, |
||
| 2778 | * or null to allow WP to run its normal queries. |
||
| 2779 | * @param WP_Query $this The WP_Query instance, passed by reference. |
||
| 2780 | */ |
||
| 2781 | $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); |
||
| 2782 | |||
| 2783 | if ( 'ids' == $q['fields'] ) { |
||
| 2784 | if ( null === $this->posts ) { |
||
| 2785 | $this->posts = $wpdb->get_col( $this->request ); |
||
| 2786 | } |
||
| 2787 | |||
| 2788 | $this->posts = array_map( 'intval', $this->posts ); |
||
| 2789 | $this->post_count = count( $this->posts ); |
||
| 2790 | $this->set_found_posts( $q, $limits ); |
||
| 2791 | |||
| 2792 | return $this->posts; |
||
| 2793 | } |
||
| 2794 | |||
| 2795 | if ( 'id=>parent' == $q['fields'] ) { |
||
| 2796 | if ( null === $this->posts ) { |
||
| 2797 | $this->posts = $wpdb->get_results( $this->request ); |
||
| 2798 | } |
||
| 2799 | |||
| 2800 | $this->post_count = count( $this->posts ); |
||
| 2801 | $this->set_found_posts( $q, $limits ); |
||
| 2802 | |||
| 2803 | $r = array(); |
||
| 2804 | foreach ( $this->posts as $key => $post ) { |
||
| 2805 | $this->posts[ $key ]->ID = (int) $post->ID; |
||
| 2806 | $this->posts[ $key ]->post_parent = (int) $post->post_parent; |
||
| 2807 | |||
| 2808 | $r[ (int) $post->ID ] = (int) $post->post_parent; |
||
| 2809 | } |
||
| 2810 | |||
| 2811 | return $r; |
||
| 2812 | } |
||
| 2813 | |||
| 2814 | if ( null === $this->posts ) { |
||
| 2815 | $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); |
||
| 2816 | |||
| 2817 | /** |
||
| 2818 | * Filters whether to split the query. |
||
| 2819 | * |
||
| 2820 | * Splitting the query will cause it to fetch just the IDs of the found posts |
||
| 2821 | * (and then individually fetch each post by ID), rather than fetching every |
||
| 2822 | * complete row at once. One massive result vs. many small results. |
||
| 2823 | * |
||
| 2824 | * @since 3.4.0 |
||
| 2825 | * |
||
| 2826 | * @param bool $split_the_query Whether or not to split the query. |
||
| 2827 | * @param WP_Query $this The WP_Query instance. |
||
| 2828 | */ |
||
| 2829 | $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); |
||
| 2830 | |||
| 2831 | if ( $split_the_query ) { |
||
| 2832 | // First get the IDs and then fill in the objects |
||
| 2833 | |||
| 2834 | $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; |
||
| 2835 | |||
| 2836 | /** |
||
| 2837 | * Filters the Post IDs SQL request before sending. |
||
| 2838 | * |
||
| 2839 | * @since 3.4.0 |
||
| 2840 | * |
||
| 2841 | * @param string $request The post ID request. |
||
| 2842 | * @param WP_Query $this The WP_Query instance. |
||
| 2843 | */ |
||
| 2844 | $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); |
||
| 2845 | |||
| 2846 | $ids = $wpdb->get_col( $this->request ); |
||
| 2847 | |||
| 2848 | if ( $ids ) { |
||
| 2849 | $this->posts = $ids; |
||
| 2850 | $this->set_found_posts( $q, $limits ); |
||
| 2851 | _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); |
||
| 2852 | } else { |
||
| 2853 | $this->posts = array(); |
||
| 2854 | } |
||
| 2855 | } else { |
||
| 2856 | $this->posts = $wpdb->get_results( $this->request ); |
||
| 2857 | $this->set_found_posts( $q, $limits ); |
||
| 2858 | } |
||
| 2859 | } |
||
| 2860 | |||
| 2861 | // Convert to WP_Post objects. |
||
| 2862 | if ( $this->posts ) { |
||
| 2863 | $this->posts = array_map( 'get_post', $this->posts ); |
||
| 2864 | } |
||
| 2865 | |||
| 2866 | View Code Duplication | if ( ! $q['suppress_filters'] ) { |
|
| 2867 | /** |
||
| 2868 | * Filters the raw post results array, prior to status checks. |
||
| 2869 | * |
||
| 2870 | * @since 2.3.0 |
||
| 2871 | * |
||
| 2872 | * @param array $posts The post results array. |
||
| 2873 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2874 | */ |
||
| 2875 | $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); |
||
| 2876 | } |
||
| 2877 | |||
| 2878 | if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { |
||
| 2879 | /** This filter is documented in wp-includes/query.php */ |
||
| 2880 | $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); |
||
| 2881 | |||
| 2882 | /** This filter is documented in wp-includes/query.php */ |
||
| 2883 | $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) ); |
||
| 2884 | |||
| 2885 | /** This filter is documented in wp-includes/query.php */ |
||
| 2886 | $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) ); |
||
| 2887 | $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; |
||
| 2888 | |||
| 2889 | /** This filter is documented in wp-includes/query.php */ |
||
| 2890 | $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); |
||
| 2891 | $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; |
||
| 2892 | |||
| 2893 | /** This filter is documented in wp-includes/query.php */ |
||
| 2894 | $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); |
||
| 2895 | |||
| 2896 | $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; |
||
| 2897 | $comments = $wpdb->get_results($comments_request); |
||
| 2898 | // Convert to WP_Comment |
||
| 2899 | $this->comments = array_map( 'get_comment', $comments ); |
||
| 2900 | $this->comment_count = count($this->comments); |
||
| 2901 | } |
||
| 2902 | |||
| 2903 | // Check post status to determine if post should be displayed. |
||
| 2904 | if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { |
||
| 2905 | $status = get_post_status($this->posts[0]); |
||
| 2906 | if ( 'attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent ) { |
||
| 2907 | $this->is_page = false; |
||
| 2908 | $this->is_single = true; |
||
| 2909 | $this->is_attachment = true; |
||
| 2910 | } |
||
| 2911 | $post_status_obj = get_post_status_object($status); |
||
| 2912 | |||
| 2913 | // If the post_status was specifically requested, let it pass through. |
||
| 2914 | if ( !$post_status_obj->public && ! in_array( $status, $q_status ) ) { |
||
| 2915 | |||
| 2916 | if ( ! is_user_logged_in() ) { |
||
| 2917 | // User must be logged in to view unpublished posts. |
||
| 2918 | $this->posts = array(); |
||
| 2919 | } else { |
||
| 2920 | if ( $post_status_obj->protected ) { |
||
| 2921 | // User must have edit permissions on the draft to preview. |
||
| 2922 | if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) { |
||
| 2923 | $this->posts = array(); |
||
| 2924 | } else { |
||
| 2925 | $this->is_preview = true; |
||
| 2926 | if ( 'future' != $status ) |
||
| 2927 | $this->posts[0]->post_date = current_time('mysql'); |
||
| 2928 | } |
||
| 2929 | } elseif ( $post_status_obj->private ) { |
||
| 2930 | if ( ! current_user_can($read_cap, $this->posts[0]->ID) ) |
||
| 2931 | $this->posts = array(); |
||
| 2932 | } else { |
||
| 2933 | $this->posts = array(); |
||
| 2934 | } |
||
| 2935 | } |
||
| 2936 | } |
||
| 2937 | |||
| 2938 | if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) { |
||
| 2939 | /** |
||
| 2940 | * Filters the single post for preview mode. |
||
| 2941 | * |
||
| 2942 | * @since 2.7.0 |
||
| 2943 | * |
||
| 2944 | * @param WP_Post $post_preview The Post object. |
||
| 2945 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 2946 | */ |
||
| 2947 | $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); |
||
| 2948 | } |
||
| 2949 | } |
||
| 2950 | |||
| 2951 | // Put sticky posts at the top of the posts array |
||
| 2952 | $sticky_posts = get_option('sticky_posts'); |
||
| 2953 | if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) { |
||
| 2954 | $num_posts = count($this->posts); |
||
| 2955 | $sticky_offset = 0; |
||
| 2956 | // Loop over posts and relocate stickies to the front. |
||
| 2957 | for ( $i = 0; $i < $num_posts; $i++ ) { |
||
| 2958 | if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { |
||
| 2959 | $sticky_post = $this->posts[$i]; |
||
| 2960 | // Remove sticky from current position |
||
| 2961 | array_splice($this->posts, $i, 1); |
||
| 2962 | // Move to front, after other stickies |
||
| 2963 | array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
||
| 2964 | // Increment the sticky offset. The next sticky will be placed at this offset. |
||
| 2965 | $sticky_offset++; |
||
| 2966 | // Remove post from sticky posts array |
||
| 2967 | $offset = array_search($sticky_post->ID, $sticky_posts); |
||
| 2968 | unset( $sticky_posts[$offset] ); |
||
| 2969 | } |
||
| 2970 | } |
||
| 2971 | |||
| 2972 | // If any posts have been excluded specifically, Ignore those that are sticky. |
||
| 2973 | if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) |
||
| 2974 | $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); |
||
| 2975 | |||
| 2976 | // Fetch sticky posts that weren't in the query results |
||
| 2977 | if ( !empty($sticky_posts) ) { |
||
| 2978 | $stickies = get_posts( array( |
||
| 2979 | 'post__in' => $sticky_posts, |
||
| 2980 | 'post_type' => $post_type, |
||
| 2981 | 'post_status' => 'publish', |
||
| 2982 | 'nopaging' => true |
||
| 2983 | ) ); |
||
| 2984 | |||
| 2985 | foreach ( $stickies as $sticky_post ) { |
||
| 2986 | array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); |
||
| 2987 | $sticky_offset++; |
||
| 2988 | } |
||
| 2989 | } |
||
| 2990 | } |
||
| 2991 | |||
| 2992 | // If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up. |
||
| 2993 | if ( ! empty( $this->comments ) ) { |
||
| 2994 | wp_queue_comments_for_comment_meta_lazyload( $this->comments ); |
||
| 2995 | } |
||
| 2996 | |||
| 2997 | View Code Duplication | if ( ! $q['suppress_filters'] ) { |
|
| 2998 | /** |
||
| 2999 | * Filters the array of retrieved posts after they've been fetched and |
||
| 3000 | * internally processed. |
||
| 3001 | * |
||
| 3002 | * @since 1.5.0 |
||
| 3003 | * |
||
| 3004 | * @param array $posts The array of retrieved posts. |
||
| 3005 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
||
| 3006 | */ |
||
| 3007 | $this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) ); |
||
| 3008 | } |
||
| 3009 | |||
| 3010 | // Ensure that any posts added/modified via one of the filters above are |
||
| 3011 | // of the type WP_Post and are filtered. |
||
| 3012 | if ( $this->posts ) { |
||
| 3013 | $this->post_count = count( $this->posts ); |
||
| 3014 | |||
| 3015 | $this->posts = array_map( 'get_post', $this->posts ); |
||
| 3016 | |||
| 3017 | if ( $q['cache_results'] ) |
||
| 3018 | update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); |
||
| 3019 | |||
| 3020 | $this->post = reset( $this->posts ); |
||
| 3021 | } else { |
||
| 3022 | $this->post_count = 0; |
||
| 3023 | $this->posts = array(); |
||
| 3024 | } |
||
| 3025 | |||
| 3026 | if ( $q['lazy_load_term_meta'] ) { |
||
| 3027 | wp_queue_posts_for_term_meta_lazyload( $this->posts ); |
||
| 3028 | } |
||
| 3029 | |||
| 3030 | return $this->posts; |
||
| 3031 | } |
||
| 3032 | |||
| 3033 | /** |
||
| 3034 | * Set up the amount of found posts and the number of pages (if limit clause was used) |
||
| 3035 | * for the current query. |
||
| 3036 | * |
||
| 3037 | * @since 3.5.0 |
||
| 3038 | * @access private |
||
| 3039 | * |
||
| 3040 | * @param array $q Query variables. |
||
| 3041 | * @param string $limits LIMIT clauses of the query. |
||
| 3042 | */ |
||
| 3043 | private function set_found_posts( $q, $limits ) { |
||
| 3077 | |||
| 3078 | /** |
||
| 3079 | * Set up the next post and iterate current post index. |
||
| 3080 | * |
||
| 3081 | * @since 1.5.0 |
||
| 3082 | * @access public |
||
| 3083 | * |
||
| 3084 | * @return WP_Post Next post. |
||
| 3085 | */ |
||
| 3086 | public function next_post() { |
||
| 3093 | |||
| 3094 | /** |
||
| 3095 | * Sets up the current post. |
||
| 3096 | * |
||
| 3097 | * Retrieves the next post, sets up the post, sets the 'in the loop' |
||
| 3098 | * property to true. |
||
| 3099 | * |
||
| 3100 | * @since 1.5.0 |
||
| 3101 | * @access public |
||
| 3102 | * |
||
| 3103 | * @global WP_Post $post |
||
| 3104 | */ |
||
| 3105 | public function the_post() { |
||
| 3122 | |||
| 3123 | /** |
||
| 3124 | * Determines whether there are more posts available in the loop. |
||
| 3125 | * |
||
| 3126 | * Calls the {@see 'loop_end'} action when the loop is complete. |
||
| 3127 | * |
||
| 3128 | * @since 1.5.0 |
||
| 3129 | * @access public |
||
| 3130 | * |
||
| 3131 | * @return bool True if posts are available, false if end of loop. |
||
| 3132 | */ |
||
| 3133 | public function have_posts() { |
||
| 3152 | |||
| 3153 | /** |
||
| 3154 | * Rewind the posts and reset post index. |
||
| 3155 | * |
||
| 3156 | * @since 1.5.0 |
||
| 3157 | * @access public |
||
| 3158 | */ |
||
| 3159 | public function rewind_posts() { |
||
| 3165 | |||
| 3166 | /** |
||
| 3167 | * Iterate current comment index and return WP_Comment object. |
||
| 3168 | * |
||
| 3169 | * @since 2.2.0 |
||
| 3170 | * @access public |
||
| 3171 | * |
||
| 3172 | * @return WP_Comment Comment object. |
||
| 3173 | */ |
||
| 3174 | public function next_comment() { |
||
| 3180 | |||
| 3181 | /** |
||
| 3182 | * Sets up the current comment. |
||
| 3183 | * |
||
| 3184 | * @since 2.2.0 |
||
| 3185 | * @access public |
||
| 3186 | * @global WP_Comment $comment Current comment. |
||
| 3187 | */ |
||
| 3188 | public function the_comment() { |
||
| 3202 | |||
| 3203 | /** |
||
| 3204 | * Whether there are more comments available. |
||
| 3205 | * |
||
| 3206 | * Automatically rewinds comments when finished. |
||
| 3207 | * |
||
| 3208 | * @since 2.2.0 |
||
| 3209 | * @access public |
||
| 3210 | * |
||
| 3211 | * @return bool True, if more comments. False, if no more posts. |
||
| 3212 | */ |
||
| 3213 | public function have_comments() { |
||
| 3222 | |||
| 3223 | /** |
||
| 3224 | * Rewind the comments, resets the comment index and comment to first. |
||
| 3225 | * |
||
| 3226 | * @since 2.2.0 |
||
| 3227 | * @access public |
||
| 3228 | */ |
||
| 3229 | public function rewind_comments() { |
||
| 3235 | |||
| 3236 | /** |
||
| 3237 | * Sets up the WordPress query by parsing query string. |
||
| 3238 | * |
||
| 3239 | * @since 1.5.0 |
||
| 3240 | * @access public |
||
| 3241 | * |
||
| 3242 | * @param string|array $query URL query string or array of query arguments. |
||
| 3243 | * @return array List of posts. |
||
| 3244 | */ |
||
| 3245 | public function query( $query ) { |
||
| 3250 | |||
| 3251 | /** |
||
| 3252 | * Retrieve queried object. |
||
| 3253 | * |
||
| 3254 | * If queried object is not set, then the queried object will be set from |
||
| 3255 | * the category, tag, taxonomy, posts page, single post, page, or author |
||
| 3256 | * query variable. After it is set up, it will be returned. |
||
| 3257 | * |
||
| 3258 | * @since 1.5.0 |
||
| 3259 | * @access public |
||
| 3260 | * |
||
| 3261 | * @return object |
||
| 3262 | */ |
||
| 3263 | public function get_queried_object() { |
||
| 3326 | |||
| 3327 | /** |
||
| 3328 | * Retrieve ID of the current queried object. |
||
| 3329 | * |
||
| 3330 | * @since 1.5.0 |
||
| 3331 | * @access public |
||
| 3332 | * |
||
| 3333 | * @return int |
||
| 3334 | */ |
||
| 3335 | public function get_queried_object_id() { |
||
| 3344 | |||
| 3345 | /** |
||
| 3346 | * Constructor. |
||
| 3347 | * |
||
| 3348 | * Sets up the WordPress query, if parameter is not empty. |
||
| 3349 | * |
||
| 3350 | * @since 1.5.0 |
||
| 3351 | * @access public |
||
| 3352 | * |
||
| 3353 | * @param string|array $query URL query string or array of vars. |
||
| 3354 | */ |
||
| 3355 | public function __construct( $query = '' ) { |
||
| 3360 | |||
| 3361 | /** |
||
| 3362 | * Make private properties readable for backward compatibility. |
||
| 3363 | * |
||
| 3364 | * @since 4.0.0 |
||
| 3365 | * @access public |
||
| 3366 | * |
||
| 3367 | * @param string $name Property to get. |
||
| 3368 | * @return mixed Property. |
||
| 3369 | */ |
||
| 3370 | public function __get( $name ) { |
||
| 3375 | |||
| 3376 | /** |
||
| 3377 | * Make private properties checkable for backward compatibility. |
||
| 3378 | * |
||
| 3379 | * @since 4.0.0 |
||
| 3380 | * @access public |
||
| 3381 | * |
||
| 3382 | * @param string $name Property to check if set. |
||
| 3383 | * @return bool Whether the property is set. |
||
| 3384 | */ |
||
| 3385 | public function __isset( $name ) { |
||
| 3390 | |||
| 3391 | /** |
||
| 3392 | * Make private/protected methods readable for backward compatibility. |
||
| 3393 | * |
||
| 3394 | * @since 4.0.0 |
||
| 3395 | * @access public |
||
| 3396 | * |
||
| 3397 | * @param callable $name Method to call. |
||
| 3398 | * @param array $arguments Arguments to pass when calling. |
||
| 3399 | * @return mixed|false Return value of the callback, false otherwise. |
||
| 3400 | */ |
||
| 3401 | public function __call( $name, $arguments ) { |
||
| 3407 | |||
| 3408 | /** |
||
| 3409 | * Is the query for an existing archive page? |
||
| 3410 | * |
||
| 3411 | * Month, Year, Category, Author, Post Type archive... |
||
| 3412 | * |
||
| 3413 | * @since 3.1.0 |
||
| 3414 | * |
||
| 3415 | * @return bool |
||
| 3416 | */ |
||
| 3417 | public function is_archive() { |
||
| 3420 | |||
| 3421 | /** |
||
| 3422 | * Is the query for an existing post type archive page? |
||
| 3423 | * |
||
| 3424 | * @since 3.1.0 |
||
| 3425 | * |
||
| 3426 | * @param mixed $post_types Optional. Post type or array of posts types to check against. |
||
| 3427 | * @return bool |
||
| 3428 | */ |
||
| 3429 | public function is_post_type_archive( $post_types = '' ) { |
||
| 3440 | |||
| 3441 | /** |
||
| 3442 | * Is the query for an existing attachment page? |
||
| 3443 | * |
||
| 3444 | * @since 3.1.0 |
||
| 3445 | * |
||
| 3446 | * @param mixed $attachment Attachment ID, title, slug, or array of such. |
||
| 3447 | * @return bool |
||
| 3448 | */ |
||
| 3449 | View Code Duplication | public function is_attachment( $attachment = '' ) { |
|
| 3471 | |||
| 3472 | /** |
||
| 3473 | * Is the query for an existing author archive page? |
||
| 3474 | * |
||
| 3475 | * If the $author parameter is specified, this function will additionally |
||
| 3476 | * check if the query is for one of the authors specified. |
||
| 3477 | * |
||
| 3478 | * @since 3.1.0 |
||
| 3479 | * |
||
| 3480 | * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames |
||
| 3481 | * @return bool |
||
| 3482 | */ |
||
| 3483 | View Code Duplication | public function is_author( $author = '' ) { |
|
| 3503 | |||
| 3504 | /** |
||
| 3505 | * Is the query for an existing category archive page? |
||
| 3506 | * |
||
| 3507 | * If the $category parameter is specified, this function will additionally |
||
| 3508 | * check if the query is for one of the categories specified. |
||
| 3509 | * |
||
| 3510 | * @since 3.1.0 |
||
| 3511 | * |
||
| 3512 | * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. |
||
| 3513 | * @return bool |
||
| 3514 | */ |
||
| 3515 | View Code Duplication | public function is_category( $category = '' ) { |
|
| 3535 | |||
| 3536 | /** |
||
| 3537 | * Is the query for an existing tag archive page? |
||
| 3538 | * |
||
| 3539 | * If the $tag parameter is specified, this function will additionally |
||
| 3540 | * check if the query is for one of the tags specified. |
||
| 3541 | * |
||
| 3542 | * @since 3.1.0 |
||
| 3543 | * |
||
| 3544 | * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. |
||
| 3545 | * @return bool |
||
| 3546 | */ |
||
| 3547 | View Code Duplication | public function is_tag( $tag = '' ) { |
|
| 3567 | |||
| 3568 | /** |
||
| 3569 | * Is the query for an existing custom taxonomy archive page? |
||
| 3570 | * |
||
| 3571 | * If the $taxonomy parameter is specified, this function will additionally |
||
| 3572 | * check if the query is for that specific $taxonomy. |
||
| 3573 | * |
||
| 3574 | * If the $term parameter is specified in addition to the $taxonomy parameter, |
||
| 3575 | * this function will additionally check if the query is for one of the terms |
||
| 3576 | * specified. |
||
| 3577 | * |
||
| 3578 | * @since 3.1.0 |
||
| 3579 | * |
||
| 3580 | * @global array $wp_taxonomies |
||
| 3581 | * |
||
| 3582 | * @param mixed $taxonomy Optional. Taxonomy slug or slugs. |
||
| 3583 | * @param mixed $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. |
||
| 3584 | * @return bool True for custom taxonomy archive pages, false for built-in taxonomies (category and tag archives). |
||
| 3585 | */ |
||
| 3586 | public function is_tax( $taxonomy = '', $term = '' ) { |
||
| 3613 | |||
| 3614 | /** |
||
| 3615 | * Whether the current URL is within the comments popup window. |
||
| 3616 | * |
||
| 3617 | * @since 3.1.0 |
||
| 3618 | * @deprecated 4.5.0 |
||
| 3619 | * |
||
| 3620 | * @return bool |
||
| 3621 | */ |
||
| 3622 | public function is_comments_popup() { |
||
| 3627 | |||
| 3628 | /** |
||
| 3629 | * Is the query for an existing date archive? |
||
| 3630 | * |
||
| 3631 | * @since 3.1.0 |
||
| 3632 | * |
||
| 3633 | * @return bool |
||
| 3634 | */ |
||
| 3635 | public function is_date() { |
||
| 3638 | |||
| 3639 | /** |
||
| 3640 | * Is the query for an existing day archive? |
||
| 3641 | * |
||
| 3642 | * @since 3.1.0 |
||
| 3643 | * |
||
| 3644 | * @return bool |
||
| 3645 | */ |
||
| 3646 | public function is_day() { |
||
| 3649 | |||
| 3650 | /** |
||
| 3651 | * Is the query for a feed? |
||
| 3652 | * |
||
| 3653 | * @since 3.1.0 |
||
| 3654 | * |
||
| 3655 | * @param string|array $feeds Optional feed types to check. |
||
| 3656 | * @return bool |
||
| 3657 | */ |
||
| 3658 | public function is_feed( $feeds = '' ) { |
||
| 3666 | |||
| 3667 | /** |
||
| 3668 | * Is the query for a comments feed? |
||
| 3669 | * |
||
| 3670 | * @since 3.1.0 |
||
| 3671 | * |
||
| 3672 | * @return bool |
||
| 3673 | */ |
||
| 3674 | public function is_comment_feed() { |
||
| 3677 | |||
| 3678 | /** |
||
| 3679 | * Is the query for the front page of the site? |
||
| 3680 | * |
||
| 3681 | * This is for what is displayed at your site's main URL. |
||
| 3682 | * |
||
| 3683 | * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. |
||
| 3684 | * |
||
| 3685 | * If you set a static page for the front page of your site, this function will return |
||
| 3686 | * true when viewing that page. |
||
| 3687 | * |
||
| 3688 | * Otherwise the same as @see WP_Query::is_home() |
||
| 3689 | * |
||
| 3690 | * @since 3.1.0 |
||
| 3691 | * |
||
| 3692 | * @return bool True, if front of site. |
||
| 3693 | */ |
||
| 3694 | public function is_front_page() { |
||
| 3703 | |||
| 3704 | /** |
||
| 3705 | * Is the query for the blog homepage? |
||
| 3706 | * |
||
| 3707 | * This is the page which shows the time based blog content of your site. |
||
| 3708 | * |
||
| 3709 | * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. |
||
| 3710 | * |
||
| 3711 | * If you set a static page for the front page of your site, this function will return |
||
| 3712 | * true only on the page you set as the "Posts page". |
||
| 3713 | * |
||
| 3714 | * @see WP_Query::is_front_page() |
||
| 3715 | * |
||
| 3716 | * @since 3.1.0 |
||
| 3717 | * |
||
| 3718 | * @return bool True if blog view homepage. |
||
| 3719 | */ |
||
| 3720 | public function is_home() { |
||
| 3723 | |||
| 3724 | /** |
||
| 3725 | * Is the query for an existing month archive? |
||
| 3726 | * |
||
| 3727 | * @since 3.1.0 |
||
| 3728 | * |
||
| 3729 | * @return bool |
||
| 3730 | */ |
||
| 3731 | public function is_month() { |
||
| 3734 | |||
| 3735 | /** |
||
| 3736 | * Is the query for an existing single page? |
||
| 3737 | * |
||
| 3738 | * If the $page parameter is specified, this function will additionally |
||
| 3739 | * check if the query is for one of the pages specified. |
||
| 3740 | * |
||
| 3741 | * @see WP_Query::is_single() |
||
| 3742 | * @see WP_Query::is_singular() |
||
| 3743 | * |
||
| 3744 | * @since 3.1.0 |
||
| 3745 | * |
||
| 3746 | * @param int|string|array $page Optional. Page ID, title, slug, path, or array of such. Default empty. |
||
| 3747 | * @return bool Whether the query is for an existing single page. |
||
| 3748 | */ |
||
| 3749 | View Code Duplication | public function is_page( $page = '' ) { |
|
| 3781 | |||
| 3782 | /** |
||
| 3783 | * Is the query for paged result and not for the first page? |
||
| 3784 | * |
||
| 3785 | * @since 3.1.0 |
||
| 3786 | * |
||
| 3787 | * @return bool |
||
| 3788 | */ |
||
| 3789 | public function is_paged() { |
||
| 3792 | |||
| 3793 | /** |
||
| 3794 | * Is the query for a post or page preview? |
||
| 3795 | * |
||
| 3796 | * @since 3.1.0 |
||
| 3797 | * |
||
| 3798 | * @return bool |
||
| 3799 | */ |
||
| 3800 | public function is_preview() { |
||
| 3803 | |||
| 3804 | /** |
||
| 3805 | * Is the query for the robots file? |
||
| 3806 | * |
||
| 3807 | * @since 3.1.0 |
||
| 3808 | * |
||
| 3809 | * @return bool |
||
| 3810 | */ |
||
| 3811 | public function is_robots() { |
||
| 3814 | |||
| 3815 | /** |
||
| 3816 | * Is the query for a search? |
||
| 3817 | * |
||
| 3818 | * @since 3.1.0 |
||
| 3819 | * |
||
| 3820 | * @return bool |
||
| 3821 | */ |
||
| 3822 | public function is_search() { |
||
| 3825 | |||
| 3826 | /** |
||
| 3827 | * Is the query for an existing single post? |
||
| 3828 | * |
||
| 3829 | * Works for any post type excluding pages. |
||
| 3830 | * |
||
| 3831 | * If the $post parameter is specified, this function will additionally |
||
| 3832 | * check if the query is for one of the Posts specified. |
||
| 3833 | * |
||
| 3834 | * @see WP_Query::is_page() |
||
| 3835 | * @see WP_Query::is_singular() |
||
| 3836 | * |
||
| 3837 | * @since 3.1.0 |
||
| 3838 | * |
||
| 3839 | * @param int|string|array $post Optional. Post ID, title, slug, path, or array of such. Default empty. |
||
| 3840 | * @return bool Whether the query is for an existing single post. |
||
| 3841 | */ |
||
| 3842 | View Code Duplication | public function is_single( $post = '' ) { |
|
| 3873 | |||
| 3874 | /** |
||
| 3875 | * Is the query for an existing single post of any post type (post, attachment, page, |
||
| 3876 | * custom post types)? |
||
| 3877 | * |
||
| 3878 | * If the $post_types parameter is specified, this function will additionally |
||
| 3879 | * check if the query is for one of the Posts Types specified. |
||
| 3880 | * |
||
| 3881 | * @see WP_Query::is_page() |
||
| 3882 | * @see WP_Query::is_single() |
||
| 3883 | * |
||
| 3884 | * @since 3.1.0 |
||
| 3885 | * |
||
| 3886 | * @param string|array $post_types Optional. Post type or array of post types. Default empty. |
||
| 3887 | * @return bool Whether the query is for an existing single post of any of the given post types. |
||
| 3888 | */ |
||
| 3889 | public function is_singular( $post_types = '' ) { |
||
| 3897 | |||
| 3898 | /** |
||
| 3899 | * Is the query for a specific time? |
||
| 3900 | * |
||
| 3901 | * @since 3.1.0 |
||
| 3902 | * |
||
| 3903 | * @return bool |
||
| 3904 | */ |
||
| 3905 | public function is_time() { |
||
| 3908 | |||
| 3909 | /** |
||
| 3910 | * Is the query for a trackback endpoint call? |
||
| 3911 | * |
||
| 3912 | * @since 3.1.0 |
||
| 3913 | * |
||
| 3914 | * @return bool |
||
| 3915 | */ |
||
| 3916 | public function is_trackback() { |
||
| 3919 | |||
| 3920 | /** |
||
| 3921 | * Is the query for an existing year archive? |
||
| 3922 | * |
||
| 3923 | * @since 3.1.0 |
||
| 3924 | * |
||
| 3925 | * @return bool |
||
| 3926 | */ |
||
| 3927 | public function is_year() { |
||
| 3930 | |||
| 3931 | /** |
||
| 3932 | * Is the query a 404 (returns no results)? |
||
| 3933 | * |
||
| 3934 | * @since 3.1.0 |
||
| 3935 | * |
||
| 3936 | * @return bool |
||
| 3937 | */ |
||
| 3938 | public function is_404() { |
||
| 3941 | |||
| 3942 | /** |
||
| 3943 | * Is the query for an embedded post? |
||
| 3944 | * |
||
| 3945 | * @since 4.4.0 |
||
| 3946 | * |
||
| 3947 | * @return bool |
||
| 3948 | */ |
||
| 3949 | public function is_embed() { |
||
| 3952 | |||
| 3953 | /** |
||
| 3954 | * Is the query the main query? |
||
| 3955 | * |
||
| 3956 | * @since 3.3.0 |
||
| 3957 | * |
||
| 3958 | * @global WP_Query $wp_query Global WP_Query instance. |
||
| 3959 | * |
||
| 3960 | * @return bool |
||
| 3961 | */ |
||
| 3962 | public function is_main_query() { |
||
| 3966 | |||
| 3967 | /** |
||
| 3968 | * Set up global post data. |
||
| 3969 | * |
||
| 3970 | * @since 4.1.0 |
||
| 3971 | * @since 4.4.0 Added the ability to pass a post ID to `$post`. |
||
| 3972 | * |
||
| 3973 | * @global int $id |
||
| 3974 | * @global WP_User $authordata |
||
| 3975 | * @global string|int|bool $currentday |
||
| 3976 | * @global string|int|bool $currentmonth |
||
| 3977 | * @global int $page |
||
| 3978 | * @global array $pages |
||
| 3979 | * @global int $multipage |
||
| 3980 | * @global int $more |
||
| 3981 | * @global int $numpages |
||
| 3982 | * |
||
| 3983 | * @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
||
| 3984 | * @return true True when finished. |
||
| 3985 | */ |
||
| 3986 | public function setup_postdata( $post ) { |
||
| 4074 | /** |
||
| 4075 | * After looping through a nested query, this function |
||
| 4076 | * restores the $post global to the current post in this query. |
||
| 4077 | * |
||
| 4078 | * @since 3.7.0 |
||
| 4079 | * |
||
| 4080 | * @global WP_Post $post |
||
| 4081 | */ |
||
| 4082 | public function reset_postdata() { |
||
| 4088 | |||
| 4089 | /** |
||
| 4090 | * Lazyload term meta for posts in the loop. |
||
| 4091 | * |
||
| 4092 | * @since 4.4.0 |
||
| 4093 | * @deprecated 4.5.0 See wp_queue_posts_for_term_meta_lazyload(). |
||
| 4094 | * |
||
| 4095 | * @param mixed $check |
||
| 4096 | * @param int $term_id |
||
| 4097 | * @return mixed |
||
| 4098 | */ |
||
| 4099 | public function lazyload_term_meta( $check, $term_id ) { |
||
| 4103 | |||
| 4104 | /** |
||
| 4105 | * Lazyload comment meta for comments in the loop. |
||
| 4106 | * |
||
| 4107 | * @since 4.4.0 |
||
| 4108 | * @deprecated 4.5.0 See wp_queue_comments_for_comment_meta_lazyload(). |
||
| 4109 | * |
||
| 4110 | * @param mixed $check |
||
| 4111 | * @param int $comment_id |
||
| 4112 | * @return mixed |
||
| 4113 | */ |
||
| 4114 | public function lazyload_comment_meta( $check, $comment_id ) { |
||
| 4118 | } |
||
| 4119 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..