Ticket #12891: query.php.r15471.2.2.diff
File query.php.r15471.2.2.diff, 44.3 KB (added by , 15 years ago) |
---|
-
wp-includes/query.php
27 27 return $wp_query->get($var); 28 28 } 29 29 30 30 31 /** 32 * Retrieve the currently-queried object. Wrapper for $wp_query->get_queried_object() 33 * 34 * @uses WP_Query::get_queried_object 35 * 36 * @since 3.1.0 37 * @access public 38 * 39 * @return object 40 */ 41 function get_queried_object() { 42 global $wp_query; 43 return $wp_query->get_queried_object(); 44 } 45 46 /** 47 * Retrieve ID of the current queried object. Wrapper for $wp_query->get_queried_object_id() 48 * 49 * @uses WP_Query::get_queried_object_id() 50 * 51 * @since 3.1.0 52 * @access public 53 * 54 * @return int 55 */ 56 function get_queried_object_id() { 57 global $wp_query; 58 return $wp_query->get_queried_object_id(); 59 } 60 61 /** 31 62 * Set query variable. 32 63 * 33 64 * @see WP_Query::set() … … 98 129 */ 99 130 100 131 /** 101 * Is query requesting an archive page.132 * Is the query for an archive page? 102 133 * 134 * Month, Year, Category, Author, Post Type archive... 135 * 136 * @see WP_Query::is_archive() 103 137 * @since 1.5.0 104 138 * @uses $wp_query 105 139 * 106 * @return bool True if page is archive.140 * @return bool 107 141 */ 108 142 function is_archive() { 109 143 global $wp_query; 110 144 111 return $wp_query->is_archive ;145 return $wp_query->is_archive(); 112 146 } 113 147 114 148 /** 115 * Is query requesting an attachment page.149 * Is the query for a post type archive page? 116 150 * 151 * @see WP_Query::is_post_type_archive() 152 * @since 3.1.0 153 * @uses $wp_query 154 * 155 * @param mixed $post_types Optional. Post type or array of posts types to check against. 156 * @return bool 157 */ 158 function is_post_type_archive( $post_types = '' ) { 159 global $wp_query; 160 161 return $wp_query->is_post_type_archive( $post_types ); 162 } 163 164 /** 165 * Is the query for an attachment page? 166 * 167 * @see WP_Query::is_attachment() 117 168 * @since 2.0.0 118 169 * @uses $wp_query 119 170 * 120 * @return bool True if page is attachment.171 * @return bool 121 172 */ 122 173 function is_attachment() { 123 174 global $wp_query; 124 175 125 return $wp_query->is_attachment ;176 return $wp_query->is_attachment(); 126 177 } 127 178 128 179 /** 129 * Is query requesting an author page.180 * Is the query for an author archive page? 130 181 * 131 * If the $author parameter is specified then the check will be expanded to 132 * include whether the queried author matches the one given in the parameter. 133 * You can match against integers and against strings. 182 * If the $author parameter is specified, this function will additionally 183 * check if the query is for one of the authors specified. 134 184 * 135 * If matching against an integer, the ID should be used of the author for the 136 * test. If the $author is an ID and matches the author page user ID, then 137 * 'true' will be returned. 138 * 139 * If matching against strings, then the test will be matched against both the 140 * nickname and user nicename and will return true on success. 141 * 185 * @see WP_Query::is_author() 142 186 * @since 1.5.0 143 187 * @uses $wp_query 144 188 * 145 * @param string|int $author Optional. Is current page this author.146 * @return bool True if page is author or $author (if set).189 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames 190 * @return bool 147 191 */ 148 function is_author( $author = '') {192 function is_author( $author = '' ) { 149 193 global $wp_query; 150 194 151 if ( !$wp_query->is_author ) 152 return false; 153 154 if ( empty($author) ) 155 return true; 156 157 $author_obj = $wp_query->get_queried_object(); 158 159 $author = (array) $author; 160 161 if ( in_array( $author_obj->ID, $author ) ) 162 return true; 163 elseif ( in_array( $author_obj->nickname, $author ) ) 164 return true; 165 elseif ( in_array( $author_obj->user_nicename, $author ) ) 166 return true; 167 168 return false; 195 return $wp_query->is_author( $author ); 169 196 } 170 197 171 198 /** 172 * Whether current page query contains a category name or given category name.199 * Is the query for a category archive page? 173 200 * 174 * The category list can contain category IDs, names, or category slugs. If any175 * of them are part of the query, then it will return true.201 * If the $category parameter is specified, this function will additionally 202 * check if the query is for one of the categories specified. 176 203 * 204 * @see WP_Query::is_category() 177 205 * @since 1.5.0 178 206 * @uses $wp_query 179 207 * 180 * @param string|array $category Optional.208 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. 181 209 * @return bool 182 210 */ 183 function is_category( $category = '') {211 function is_category( $category = '' ) { 184 212 global $wp_query; 185 213 186 if ( !$wp_query->is_category ) 187 return false; 188 189 if ( empty($category) ) 190 return true; 191 192 $cat_obj = $wp_query->get_queried_object(); 193 194 $category = (array) $category; 195 196 if ( in_array( $cat_obj->term_id, $category ) ) 197 return true; 198 elseif ( in_array( $cat_obj->name, $category ) ) 199 return true; 200 elseif ( in_array( $cat_obj->slug, $category ) ) 201 return true; 202 203 return false; 214 return $wp_query->is_category( $category ); 204 215 } 205 216 206 217 /** 207 * Whether the current page query has the given tag slug or contains tag.218 * Is the query for a tag archive page? 208 219 * 220 * If the $tag parameter is specified, this function will additionally 221 * check if the query is for one of the tags specified. 222 * 223 * @see WP_Query::is_tag() 209 224 * @since 2.3.0 210 225 * @uses $wp_query 211 226 * 212 * @param string|array $slug Optional. Single tag or list of tags to check for.227 * @param mixed $slug Optional. Tag slug or array of slugs. 213 228 * @return bool 214 229 */ 215 230 function is_tag( $slug = '' ) { 216 231 global $wp_query; 217 232 218 if ( !$wp_query->is_tag ) 219 return false; 220 221 if ( empty( $slug ) ) 222 return true; 223 224 $tag_obj = $wp_query->get_queried_object(); 225 226 $slug = (array) $slug; 227 228 if ( in_array( $tag_obj->slug, $slug ) ) 229 return true; 230 231 return false; 233 return $wp_query->is_tag( $slug ); 232 234 } 233 235 234 236 /** 235 * Whether the current query is for the given taxonomy and/or term.237 * Is the query for a taxonomy archive page? 236 238 * 237 * If no taxonomy argument is set, returns true if any taxonomy is queried. 238 * If the taxonomy argument is passed but no term argument, returns true 239 * if the taxonomy or taxonomies in the argument are being queried. 240 * If both taxonomy and term arguments are passed, returns true 241 * if the current query is for a term contained in the terms argument 242 * which has a taxonomy contained in the taxonomy argument. 239 * If the $taxonomy parameter is specified, this function will additionally 240 * check if the query is for that specific $taxonomy. 243 241 * 242 * If the $term parameter is specified in addition to the $taxonomy parameter, 243 * this function will additionally check if the query is for one of the terms 244 * specified. 245 * 246 * @see WP_Query::is_tax() 244 247 * @since 2.5.0 245 248 * @uses $wp_query 246 249 * 247 * @param string|array $taxonomy Optional. Taxonomy slug or slugs to check in current query.248 * @param int|array|string $term. Optional. A single or array of, The term's ID, Name or Slug250 * @param mixed $taxonomy Optional. Taxonomy slug or slugs. 251 * @param mixed $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. 249 252 * @return bool 250 253 */ 251 254 function is_tax( $taxonomy = '', $term = '' ) { 252 255 global $wp_query, $wp_taxonomies; 253 256 254 $queried_object = $wp_query->get_queried_object(); 255 $tax_array = array_intersect(array_keys($wp_taxonomies), (array) $taxonomy); 256 $term_array = (array) $term; 257 258 if ( !$wp_query->is_tax ) 259 return false; 260 261 if ( empty( $taxonomy ) ) 262 return true; 263 264 if ( empty( $term ) ) // Only a Taxonomy provided 265 return isset($queried_object->taxonomy) && count( $tax_array ) && in_array($queried_object->taxonomy, $tax_array); 266 267 return isset($queried_object->term_id) && 268 count(array_intersect( 269 array($queried_object->term_id, $queried_object->name, $queried_object->slug), 270 $term_array 271 )); 257 return $wp_query->is_tax( $taxonomy, $term ); 272 258 } 273 259 274 260 /** 275 261 * Whether the current URL is within the comments popup window. 276 262 * 263 * @see WP_Query::is_comments_popup() 277 264 * @since 1.5.0 278 265 * @uses $wp_query 279 266 * … … 282 269 function is_comments_popup() { 283 270 global $wp_query; 284 271 285 return $wp_query->is_comments_popup ;272 return $wp_query->is_comments_popup(); 286 273 } 287 274 288 275 /** 289 * Whether current URL is based on a date.276 * Is the query for a date archive? 290 277 * 278 * @see WP_Query::is_date() 291 279 * @since 1.5.0 292 280 * @uses $wp_query 293 281 * … … 296 284 function is_date() { 297 285 global $wp_query; 298 286 299 return $wp_query->is_date ;287 return $wp_query->is_date(); 300 288 } 301 289 302 290 /** 303 * Whether current blog URL contains a day.291 * Is the query for a day archive? 304 292 * 293 * @see WP_Query::is_day() 305 294 * @since 1.5.0 306 295 * @uses $wp_query 307 296 * … … 310 299 function is_day() { 311 300 global $wp_query; 312 301 313 return $wp_query->is_day ;302 return $wp_query->is_day(); 314 303 } 315 304 316 305 /** 317 * Whether current page query is feed URL.306 * Is the query for a feed? 318 307 * 308 * @see WP_Query::is_feed() 319 309 * @since 1.5.0 320 310 * @uses $wp_query 321 311 * … … 324 314 function is_feed() { 325 315 global $wp_query; 326 316 327 return $wp_query->is_feed ;317 return $wp_query->is_feed(); 328 318 } 329 319 330 320 /** 331 * Whether current page query is comment feed URL.321 * Is the query for a comments feed? 332 322 * 323 * @see WP_Query::is_comments_feed() 333 324 * @since 3.0.0 334 325 * @uses $wp_query 335 326 * … … 338 329 function is_comment_feed() { 339 330 global $wp_query; 340 331 341 return $wp_query->is_comment_feed ;332 return $wp_query->is_comment_feed(); 342 333 } 343 334 344 335 /** 345 * Whether current page query is the front of the site.336 * Is the query for the front page of the site? 346 337 * 338 * This is for what is displayed at your site's main URL. 339 * 340 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. 341 * 342 * If you set a static page for the front page of your site, this function will return 343 * true when viewing that page. 344 * 345 * Otherwise the same as @see is_home() 346 * 347 * @see WP_Query::is_front_page() 347 348 * @since 2.5.0 348 349 * @uses is_home() 349 350 * @uses get_option() … … 351 352 * @return bool True, if front of site. 352 353 */ 353 354 function is_front_page() { 354 // most likely case 355 if ( 'posts' == get_option('show_on_front') && is_home() ) 356 return true; 357 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') && is_page(get_option('page_on_front')) ) 358 return true; 359 else 360 return false; 355 global $wp_query; 356 357 return $wp_query->is_front_page(); 361 358 } 362 359 363 360 /** 364 * Whether current page view is the blog homepage.361 * Is the query for the blog homepage? 365 362 * 366 * This is the page which is showing the time based blog content of your site 367 * so if you set a static page for the front page of your site then this will 368 * only be true on the page which you set as the "Posts page" in Reading Settings. 363 * This is the page which shows the time based blog content of your site. 369 364 * 365 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. 366 * 367 * If you set a static page for the front page of your site, this function will return 368 * true only on the page you set as the "Posts page". 369 * 370 * @see is_front_page() 371 * 372 * @see WP_Query::is_home() 370 373 * @since 1.5.0 371 374 * @uses $wp_query 372 375 * … … 375 378 function is_home() { 376 379 global $wp_query; 377 380 378 return $wp_query->is_home ;381 return $wp_query->is_home(); 379 382 } 380 383 381 384 /** 382 * Whether current page query contains a month.385 * Is the query for a month archive? 383 386 * 387 * @see WP_Query::is_month() 384 388 * @since 1.5.0 385 389 * @uses $wp_query 386 390 * … … 389 393 function is_month() { 390 394 global $wp_query; 391 395 392 return $wp_query->is_month ;396 return $wp_query->is_month(); 393 397 } 394 398 395 399 /** 396 * Whether query is page or contains given page(s).400 * Is the query for a single Page? 397 401 * 398 * Calls the function without any parameters will only test whether the current 399 * query is of the page type. Either a list or a single item can be tested 400 * against for whether the query is a page and also is the value or one of the 401 * values in the page parameter. 402 * If the $page parameter is specified, this function will additionally 403 * check if the query is for one of the Pages specified. 402 404 * 403 * The parameter can contain the page ID, page title, or page name. The404 * parameter can also be an array of those three values.405 * @see is_single() 406 * @see is_singular() 405 407 * 408 * @see WP_Query::is_single() 406 409 * @since 1.5.0 407 410 * @uses $wp_query 408 411 * 409 * @param mixed $page Either page or list of pages to test against.412 * @param mixed $page Page ID, title, slug, or array of Page IDs, titles, and slugs. 410 413 * @return bool 411 414 */ 412 function is_page( $page = '') {415 function is_page( $page = '' ) { 413 416 global $wp_query; 414 417 415 if ( !$wp_query->is_page ) 416 return false; 417 418 if ( empty($page) ) 419 return true; 420 421 $page_obj = $wp_query->get_queried_object(); 422 423 $page = (array) $page; 424 425 if ( in_array( $page_obj->ID, $page ) ) 426 return true; 427 elseif ( in_array( $page_obj->post_title, $page ) ) 428 return true; 429 else if ( in_array( $page_obj->post_name, $page ) ) 430 return true; 431 432 return false; 418 return $wp_query->is_page( $page ); 433 419 } 434 420 435 421 /** 436 * Whether query contains multiple pages for the results.422 * Is the query for paged result and not for the first page? 437 423 * 424 * @see WP_Query::is_paged() 438 425 * @since 1.5.0 439 426 * @uses $wp_query 440 427 * … … 443 430 function is_paged() { 444 431 global $wp_query; 445 432 446 return $wp_query->is_paged ;433 return $wp_query->is_paged(); 447 434 } 448 435 449 436 /** 450 * Whether the current page was created by a plugin.437 * Is the query for a post or page preview? 451 438 * 452 * The plugin can set this by using the global $plugin_page and setting it to 453 * true. 454 * 455 * @since 1.5.0 456 * @global bool $plugin_page Used by plugins to tell the query that current is a plugin page. 457 * 458 * @return bool 459 */ 460 function is_plugin_page() { 461 global $plugin_page; 462 463 if ( isset($plugin_page) ) 464 return true; 465 466 return false; 467 } 468 469 /** 470 * Whether the current query is preview of post or page. 471 * 439 * @see WP_Query::is_preview() 472 440 * @since 2.0.0 473 441 * @uses $wp_query 474 442 * … … 477 445 function is_preview() { 478 446 global $wp_query; 479 447 480 return $wp_query->is_preview ;448 return $wp_query->is_preview(); 481 449 } 482 450 483 451 /** 484 * Whether the current query post is robots.452 * Is the query for the robots file? 485 453 * 454 * @see WP_Query::is_robots() 486 455 * @since 2.1.0 487 456 * @uses $wp_query 488 457 * … … 491 460 function is_robots() { 492 461 global $wp_query; 493 462 494 return $wp_query->is_robots ;463 return $wp_query->is_robots(); 495 464 } 496 465 497 466 /** 498 * Whether current query is the result of a user search.467 * Is the query for a search? 499 468 * 469 * @see WP_Query::is_search() 500 470 * @since 1.5.0 501 471 * @uses $wp_query 502 472 * … … 505 475 function is_search() { 506 476 global $wp_query; 507 477 508 return $wp_query->is_search ;478 return $wp_query->is_search(); 509 479 } 510 480 511 481 /** 512 * Whether the current page query is single page.482 * Is the query for a single post? 513 483 * 514 * The parameter can contain the post ID, post title, or post name. The515 * parameter can also be an array of those three values.484 * If the $post parameter is specified, this function will additionally 485 * check if the query is for one of the Posts specified. 516 486 * 517 * This applies to other post types, attachments, pages, posts. Just means that 518 * the current query has only a single object. 487 * Can also be used for attachments or any other post type except pages. 519 488 * 489 * @see is_page() 490 * @see is_singular() 491 * 492 * @see WP_Query::is_single() 520 493 * @since 1.5.0 521 494 * @uses $wp_query 522 495 * 523 * @param mixed $post Either post or list of posts to test against.496 * @param mixed $post Post ID, title, slug, or array of Post IDs, titles, and slugs. 524 497 * @return bool 525 498 */ 526 function is_single( $post = '') {499 function is_single( $post = '' ) { 527 500 global $wp_query; 528 501 529 if ( !$wp_query->is_single ) 530 return false; 531 532 if ( empty($post) ) 533 return true; 534 535 $post_obj = $wp_query->get_queried_object(); 536 537 $post = (array) $post; 538 539 if ( in_array( $post_obj->ID, $post ) ) 540 return true; 541 elseif ( in_array( $post_obj->post_title, $post ) ) 542 return true; 543 elseif ( in_array( $post_obj->post_name, $post ) ) 544 return true; 545 546 return false; 502 return $wp_query->is_single( $post ); 547 503 } 548 504 549 505 /** 550 * Whether is single post, is a page, or is an attachment.506 * Is the query for a single post of any post type (post, attachment, page, ... )? 551 507 * 508 * If the $post_types parameter is specified, this function will additionally 509 * check if the query is for one of the Posts Types specified. 510 * 511 * @see is_page() 512 * @see is_single() 513 * 514 * @see WP_Query::is_singular() 552 515 * @since 1.5.0 553 516 * @uses $wp_query 554 517 * 555 * @param string|array $post_types Optional. Post type or types to check in current query.518 * @param mixed $post_types Optional. Post Type or array of Post Types 556 519 * @return bool 557 520 */ 558 function is_singular( $post_types = '') {521 function is_singular( $post_types = '' ) { 559 522 global $wp_query; 560 523 561 if ( empty($post_types) || !$wp_query->is_singular ) 562 return $wp_query->is_singular; 563 564 $post_obj = $wp_query->get_queried_object(); 565 566 return in_array($post_obj->post_type, (array) $post_types); 524 return $wp_query->is_singular( $post_types ); 567 525 } 568 526 569 527 /** 570 * Whether the query contains a time.528 * Is the query for a specific time? 571 529 * 530 * @see WP_Query::is_time() 572 531 * @since 1.5.0 573 532 * @uses $wp_query 574 533 * … … 577 536 function is_time() { 578 537 global $wp_query; 579 538 580 return $wp_query->is_time ;539 return $wp_query->is_time(); 581 540 } 582 541 583 542 /** 584 * Whether the query is a trackback.543 * Is the query for a trackback endpoint call? 585 544 * 545 * @see WP_Query::is_trackback() 586 546 * @since 1.5.0 587 547 * @uses $wp_query 588 548 * … … 591 551 function is_trackback() { 592 552 global $wp_query; 593 553 594 return $wp_query->is_trackback ;554 return $wp_query->is_trackback(); 595 555 } 596 556 597 557 /** 598 * Whether the query contains a year.558 * Is the query for a specific year? 599 559 * 560 * @see WP_Query::is_year() 600 561 * @since 1.5.0 601 562 * @uses $wp_query 602 563 * … … 605 566 function is_year() { 606 567 global $wp_query; 607 568 608 return $wp_query->is_year ;569 return $wp_query->is_year(); 609 570 } 610 571 611 572 /** 612 * Whether current page query is a 404 and no results for WordPress query.573 * Is the query a 404 (returns no results)? 613 574 * 575 * @see WP_Query::is_404() 614 576 * @since 1.5.0 615 577 * @uses $wp_query 616 578 * 617 * @return bool True, if nothing is found matching WordPress Query.579 * @return bool 618 580 */ 619 581 function is_404() { 620 582 global $wp_query; 621 583 622 return $wp_query->is_404 ;584 return $wp_query->is_404(); 623 585 } 624 586 625 587 /* … … 729 691 class WP_Query { 730 692 731 693 /** 732 * Query string694 * Query vars set by the user 733 695 * 734 696 * @since 1.5.0 735 697 * @access public 736 * @var string698 * @var array 737 699 */ 738 700 var $query; 739 701 740 702 /** 741 * Query search variables set by the user.703 * Query vars, after parsing 742 704 * 743 705 * @since 1.5.0 744 706 * @access public … … 816 778 * 817 779 * @since 1.5.0 818 780 * @access public 819 * @var int781 * @var object 820 782 */ 821 783 var $post; 822 784 … … 1064 1026 var $is_comments_popup = false; 1065 1027 1066 1028 /** 1029 * Set if query is paged 1030 * 1031 * @since 1.5.0 1032 * @access public 1033 * @var bool 1034 */ 1035 var $is_paged = false; 1036 1037 /** 1067 1038 * Set if query is part of administration page. 1068 1039 * 1069 1040 * @since 1.5.0 … … 1111 1082 var $is_posts_page = false; 1112 1083 1113 1084 /** 1085 * Set if query is for a post type archive. 1086 * 1087 * @since 3.1.0 1088 * @access public 1089 * @var bool 1090 */ 1091 var $is_post_type_archive = false; 1092 1093 /** 1114 1094 * Resets query flags to false. 1115 1095 * 1116 1096 * The query flags are what page info WordPress was able to figure out. … … 1120 1100 */ 1121 1101 function init_query_flags() { 1122 1102 $this->is_single = false; 1103 $this->is_preview = false; 1123 1104 $this->is_page = false; 1124 1105 $this->is_archive = false; 1125 1106 $this->is_date = false; … … 1137 1118 $this->is_trackback = false; 1138 1119 $this->is_home = false; 1139 1120 $this->is_404 = false; 1121 $this->is_comments_popup = false; 1140 1122 $this->is_paged = false; 1141 1123 $this->is_admin = false; 1142 1124 $this->is_attachment = false; 1143 1125 $this->is_singular = false; 1144 1126 $this->is_robots = false; 1145 1127 $this->is_posts_page = false; 1128 $this->is_post_type_archive = false; 1146 1129 } 1147 1130 1148 1131 /** … … 1155 1138 unset($this->posts); 1156 1139 unset($this->query); 1157 1140 $this->query_vars = array(); 1141 $this->tax_query = array(); 1142 $this->meta_query = array(); 1158 1143 unset($this->queried_object); 1159 1144 unset($this->queried_object_id); 1160 1145 $this->post_count = 0; 1161 1146 $this->current_post = -1; 1162 1147 $this->in_the_loop = false; 1148 unset( $this->request ); 1149 unset( $this->post ); 1150 unset( $this->comments ); 1151 unset( $this->comment ); 1152 $this->comment_count = 0; 1153 $this->current_comment = -1; 1154 $this->found_posts = 0; 1155 $this->max_num_pages = 0; 1156 $this->max_num_comment_pages = 0; 1163 1157 1164 1158 $this->init_query_flags(); 1165 1159 } … … 1218 1212 , 'preview' 1219 1213 , 's' 1220 1214 , 'sentence' 1215 , 'fields' 1221 1216 ); 1222 1217 1223 1218 foreach ( $keys as $key ) { 1224 if ( !isset($array[$key]) )1219 if ( !isset($array[$key]) ) 1225 1220 $array[$key] = ''; 1226 1221 } 1227 1222 … … 1229 1224 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and'); 1230 1225 1231 1226 foreach ( $array_keys as $key ) { 1232 if ( !isset($array[$key]) )1227 if ( !isset($array[$key]) ) 1233 1228 $array[$key] = array(); 1234 1229 } 1235 1230 return $array; … … 1246 1241 function parse_query($query) { 1247 1242 if ( !empty($query) || !isset($this->query) ) { 1248 1243 $this->init(); 1249 if ( is_array($query) ) 1250 $this->query_vars = $query; 1251 else 1252 parse_str($query, $this->query_vars); 1253 $this->query = $query; 1244 $this->query = $this->query_vars = wp_parse_args($query); 1254 1245 } 1255 1246 1256 1247 $this->query_vars = $this->fill_query_vars($this->query_vars); … … 1296 1287 } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) { 1297 1288 $this->is_page = true; 1298 1289 $this->is_single = false; 1299 } elseif ( !empty($qv['s']) ) {1300 $this->is_search = true;1301 1290 } else { 1302 // Look for archive queries. Dates, categories, authors .1291 // Look for archive queries. Dates, categories, authors, search, post type archives. 1303 1292 1293 if ( !empty($qv['s']) ) { 1294 $this->is_search = true; 1295 } 1296 1304 1297 if ( '' !== $qv['second'] ) { 1305 1298 $this->is_time = true; 1306 1299 $this->is_date = true; … … 1354 1347 $this->is_date = true; 1355 1348 } 1356 1349 1357 if ( empty($qv['cat']) || ($qv['cat'] == '0') ) {1350 if ( empty($qv['cat']) || ($qv['cat'] == '0') ) 1358 1351 $this->is_category = false; 1359 } else { 1360 if ( strpos($qv['cat'], '-') !== false ) { 1361 $this->is_category = false; 1362 } else { 1363 $this->is_category = true; 1364 } 1365 } 1352 else 1353 $this->is_category = strpos($qv['cat'], '-') === false; 1366 1354 1367 if ( '' != $qv['category_name']) {1355 if ( !empty($qv['category_name']) ) { 1368 1356 $this->is_category = true; 1369 1357 } 1370 1358 1371 if ( !is_array($qv['category__in']) ||empty($qv['category__in']) ) {1359 if ( empty($qv['category__in']) ) { 1372 1360 $qv['category__in'] = array(); 1373 1361 } else { 1374 $qv['category__in'] = array_map('absint', $qv['category__in']);1362 $qv['category__in'] = array_map('absint', (array) $qv['category__in']); 1375 1363 $this->is_category = true; 1376 1364 } 1377 1365 1378 if ( !is_array($qv['category__not_in']) ||empty($qv['category__not_in']) ) {1366 if ( empty($qv['category__not_in']) ) { 1379 1367 $qv['category__not_in'] = array(); 1380 1368 } else { 1381 $qv['category__not_in'] = array_map('absint', $qv['category__not_in']);1369 $qv['category__not_in'] = array_map('absint', (array) $qv['category__not_in']); 1382 1370 } 1383 1371 1384 if ( !is_array($qv['category__and']) ||empty($qv['category__and']) ) {1372 if ( empty($qv['category__and']) ) { 1385 1373 $qv['category__and'] = array(); 1386 1374 } else { 1387 $qv['category__and'] = array_map('absint', $qv['category__and']);1375 $qv['category__and'] = array_map('absint', (array) $qv['category__and']); 1388 1376 $this->is_category = true; 1389 1377 } 1390 1378 … … 1392 1380 $this->is_tag = true; 1393 1381 1394 1382 $qv['tag_id'] = absint($qv['tag_id']); 1395 if ( 1383 if ( !empty($qv['tag_id']) ) 1396 1384 $this->is_tag = true; 1397 1385 1398 if ( !is_array($qv['tag__in']) ||empty($qv['tag__in']) ) {1386 if ( empty($qv['tag__in']) ) { 1399 1387 $qv['tag__in'] = array(); 1400 1388 } else { 1401 $qv['tag__in'] = array_map('absint', $qv['tag__in']);1389 $qv['tag__in'] = array_map('absint', (array) $qv['tag__in']); 1402 1390 $this->is_tag = true; 1403 1391 } 1404 1392 1405 if ( !is_array($qv['tag__not_in']) ||empty($qv['tag__not_in']) ) {1393 if ( empty($qv['tag__not_in']) ) { 1406 1394 $qv['tag__not_in'] = array(); 1407 1395 } else { 1408 $qv['tag__not_in'] = array_map('absint', $qv['tag__not_in']);1396 $qv['tag__not_in'] = array_map('absint', (array) $qv['tag__not_in']); 1409 1397 } 1410 1398 1411 1399 if ( !is_array($qv['tag__and']) || empty($qv['tag__and']) ) { 1412 1400 $qv['tag__and'] = array(); 1413 1401 } else { 1414 $qv['tag__and'] = array_map('absint', $qv['tag__and']);1415 $this->is_ category= true;1402 $qv['tag__and'] = array_map('absint', (array) $qv['tag__and']); 1403 $this->is_tag = true; 1416 1404 } 1417 1405 1418 if ( !is_array($qv['tag_slug__in']) ||empty($qv['tag_slug__in']) ) {1406 if ( empty($qv['tag_slug__in']) ) { 1419 1407 $qv['tag_slug__in'] = array(); 1420 1408 } else { 1421 $qv['tag_slug__in'] = array_map('sanitize_title', $qv['tag_slug__in']);1409 $qv['tag_slug__in'] = array_map('sanitize_title', (array) $qv['tag_slug__in']); 1422 1410 $this->is_tag = true; 1423 1411 } 1424 1412 1425 if ( !is_array($qv['tag_slug__and']) ||empty($qv['tag_slug__and']) ) {1413 if ( empty($qv['tag_slug__and']) ) { 1426 1414 $qv['tag_slug__and'] = array(); 1427 1415 } else { 1428 $qv['tag_slug__and'] = array_map('sanitize_title', $qv['tag_slug__and']);1416 $qv['tag_slug__and'] = array_map('sanitize_title', (array) $qv['tag_slug__and']); 1429 1417 $this->is_tag = true; 1430 1418 } 1431 1419 … … 1449 1437 $this->is_author = true; 1450 1438 } 1451 1439 1452 if ( '' != $qv['author_name'] ) {1440 if ( '' != $qv['author_name'] ) 1453 1441 $this->is_author = true; 1442 1443 if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) { 1444 $post_type_obj = get_post_type_object( $qv['post_type'] ); 1445 if ( ! empty( $post_type_obj->has_archive ) ) 1446 $this->is_post_type_archive = true; 1454 1447 } 1455 1448 1456 if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax))1449 if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) 1457 1450 $this->is_archive = true; 1458 1451 } 1459 1452 … … 1528 1521 1529 1522 if ( !empty($qv['post_type']) ) { 1530 1523 if ( is_array($qv['post_type']) ) 1531 $qv['post_type'] = array_map('sanitize_ user', $qv['post_type'], array(true));1524 $qv['post_type'] = array_map('sanitize_key', $qv['post_type']); 1532 1525 else 1533 $qv['post_type'] = sanitize_ user($qv['post_type'], true);1526 $qv['post_type'] = sanitize_key($qv['post_type']); 1534 1527 } 1535 1528 1536 1529 if ( !empty($qv['post_status']) ) … … 1625 1618 $join = ''; 1626 1619 $search = ''; 1627 1620 $groupby = ''; 1628 $fields = "$wpdb->posts.*";1621 $fields = ''; 1629 1622 $post_status_join = false; 1630 1623 $page = 1; 1631 1624 1632 if ( !isset($q['caller_get_posts']) ) 1633 $q['caller_get_posts'] = false; 1625 if ( isset( $q['caller_get_posts'] ) ) { 1626 _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) ); 1627 if ( !isset( $q['ignore_sticky_posts'] ) ) 1628 $q['ignore_sticky_posts'] = $q['caller_get_posts']; 1629 } 1634 1630 1631 if ( !isset( $q['ignore_sticky_posts'] ) ) 1632 $q['ignore_sticky_posts'] = false; 1633 1635 1634 if ( !isset($q['suppress_filters']) ) 1636 1635 $q['suppress_filters'] = false; 1637 1636 … … 1700 1699 else 1701 1700 $q['no_found_rows'] = false; 1702 1701 1702 switch ( $q['fields'] ) { 1703 case 'ids': 1704 $fields = "$wpdb->posts.ID"; 1705 break; 1706 case 'id=>parent': 1707 $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent"; 1708 break; 1709 default: 1710 $fields = "$wpdb->posts.*"; 1711 } 1712 1703 1713 // If a month is specified in the querystring, load that month 1704 1714 if ( $q['m'] ) { 1705 1715 $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); … … 1757 1767 } 1758 1768 1759 1769 if ( '' != $q['name'] ) { 1760 $q['name'] = sanitize_title ($q['name']);1770 $q['name'] = sanitize_title_for_query( $q['name'] ); 1761 1771 $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'"; 1762 1772 } elseif ( '' != $q['pagename'] ) { 1763 1773 if ( isset($this->queried_object_id) ) { … … 1785 1795 1786 1796 $page_for_posts = get_option('page_for_posts'); 1787 1797 if ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) { 1788 $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); 1789 $page_paths = '/' . trim($q['pagename'], '/'); 1790 $q['pagename'] = sanitize_title(basename($page_paths)); 1798 $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); 1791 1799 $q['name'] = $q['pagename']; 1792 1800 $where .= " AND ($wpdb->posts.ID = '$reqpage')"; 1793 1801 $reqpage_obj = get_page($reqpage); … … 1799 1807 } 1800 1808 } 1801 1809 } elseif ( '' != $q['attachment'] ) { 1802 $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); 1803 $attach_paths = '/' . trim($q['attachment'], '/'); 1804 $q['attachment'] = sanitize_title(basename($attach_paths)); 1810 $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); 1805 1811 $q['name'] = $q['attachment']; 1806 1812 $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'"; 1807 1813 } … … 2102 2108 $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailling slash 2103 2109 } 2104 2110 } 2105 $q['author_name'] = sanitize_title ($q['author_name']);2111 $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); 2106 2112 $q['author'] = get_user_by('slug', $q['author_name']); 2107 2113 if ( $q['author'] ) 2108 2114 $q['author'] = $q['author']->ID; … … 2178 2184 $q['orderby'] = "$wpdb->posts.post_date ".$q['order']; 2179 2185 } 2180 2186 2181 if ( is_array( $post_type) ) {2187 if ( is_array( $post_type ) ) { 2182 2188 $post_type_cap = 'multiple_post_type'; 2183 2189 } else { 2184 $post_type_object = get_post_type_object ( $post_type ); 2185 if ( !empty($post_type_object) ) 2186 $post_type_cap = $post_type_object->capability_type; 2187 else 2190 $post_type_object = get_post_type_object( $post_type ); 2191 if ( empty( $post_type_object ) ) 2188 2192 $post_type_cap = $post_type; 2189 2193 } 2190 2194 … … 2211 2215 $post_type_object = get_post_type_object ( 'post' ); 2212 2216 } 2213 2217 2214 if ( !empty($post_type_object) ) { 2215 $post_type_cap = $post_type_object->capability_type; 2218 if ( ! empty( $post_type_object ) ) { 2216 2219 $edit_cap = $post_type_object->cap->edit_post; 2217 2220 $read_cap = $post_type_object->cap->read_post; 2218 2221 $edit_others_cap = $post_type_object->cap->edit_others_posts; … … 2405 2408 $groupby = 'GROUP BY ' . $groupby; 2406 2409 if ( !empty( $orderby ) ) 2407 2410 $orderby = 'ORDER BY ' . $orderby; 2411 2408 2412 $found_rows = ''; 2409 2413 if ( !$q['no_found_rows'] && !empty($limits) ) 2410 2414 $found_rows = 'SQL_CALC_FOUND_ROWS'; … … 2413 2417 if ( !$q['suppress_filters'] ) 2414 2418 $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); 2415 2419 2420 if ( 'ids' == $q['fields'] ) { 2421 $this->posts = $wpdb->get_col($this->request); 2422 2423 return $this->posts; 2424 } 2425 2426 if ( 'id=>parent' == $q['fields'] ) { 2427 $this->posts = $wpdb->get_results($this->request); 2428 2429 $r = array(); 2430 foreach ( $this->posts as $post ) 2431 $r[ $post->ID ] = $post->post_parent; 2432 2433 return $r; 2434 } 2435 2416 2436 $this->posts = $wpdb->get_results($this->request); 2437 2417 2438 // Raw results filter. Prior to status checks. 2418 2439 if ( !$q['suppress_filters'] ) 2419 2440 $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) ); … … 2472 2493 2473 2494 // Put sticky posts at the top of the posts array 2474 2495 $sticky_posts = get_option('sticky_posts'); 2475 if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q[' caller_get_posts'] ) {2496 if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) { 2476 2497 $num_posts = count($this->posts); 2477 2498 $sticky_offset = 0; 2478 2499 // Loop over posts and relocate stickies to the front. … … 2604 2625 2605 2626 /** 2606 2627 * Rewind the posts and reset post index. 2628 2607 2629 * 2608 2630 * @since 1.5.0 2609 2631 * @access public … … 2735 2757 if ( is_wp_error($term) || empty($term) ) 2736 2758 return NULL; 2737 2759 $term = $term[0]; 2738 $this->queried_object = $term; 2739 $this->queried_object_id = $term->term_id; 2760 if ( $term && ! is_wp_error($term) ) { 2761 $this->queried_object = $term; 2762 $this->queried_object_id = $term->term_id; 2763 } 2740 2764 } elseif ( $this->is_posts_page ) { 2741 2765 $page_for_posts = get_option('page_for_posts'); 2742 2766 $this->queried_object = & get_page( $page_for_posts ); … … 2791 2815 $this->query($query); 2792 2816 } 2793 2817 } 2818 2819 /** 2820 * Is the query for an archive page? 2821 * 2822 * Month, Year, Category, Author, Post Type archive... 2823 * 2824 * @since 3.1.0 2825 * 2826 * @return bool 2827 */ 2828 function is_archive() { 2829 return (bool) $this->is_archive; 2830 } 2831 2832 /** 2833 * Is the query for a post type archive page? 2834 * 2835 * @since 3.1.0 2836 * 2837 * @param mixed $post_types Optional. Post type or array of posts types to check against. 2838 * @return bool 2839 */ 2840 function is_post_type_archive( $post_types = '' ) { 2841 if ( empty( $post_types ) || !$this->is_post_type_archive ) 2842 return (bool) $this->is_post_type_archive; 2843 2844 if ( ! isset( $this->posts[0] ) ) 2845 return false; 2846 2847 $post = $this->posts[0]; 2848 2849 return in_array( $post->post_type, (array) $post_types ); 2850 } 2851 2852 /** 2853 * Is the query for an attachment page? 2854 * 2855 * @since 3.1.0 2856 * 2857 * @return bool 2858 */ 2859 function is_attachment() { 2860 return (bool) $this->is_attachment; 2861 } 2862 2863 /** 2864 * Is the query for an author archive page? 2865 * 2866 * If the $author parameter is specified, this function will additionally 2867 * check if the query is for one of the authors specified. 2868 * 2869 * @since 3.1.0 2870 * 2871 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames 2872 * @return bool 2873 */ 2874 function is_author( $author = '' ) { 2875 if ( !$this->is_author ) 2876 return false; 2877 2878 if ( empty($author) ) 2879 return true; 2880 2881 $author_obj = $this->get_queried_object(); 2882 2883 $author = (array) $author; 2884 2885 if ( in_array( $author_obj->ID, $author ) ) 2886 return true; 2887 elseif ( in_array( $author_obj->nickname, $author ) ) 2888 return true; 2889 elseif ( in_array( $author_obj->user_nicename, $author ) ) 2890 return true; 2891 2892 return false; 2893 } 2894 2895 /** 2896 * Is the query for a category archive page? 2897 * 2898 * If the $category parameter is specified, this function will additionally 2899 * check if the query is for one of the categories specified. 2900 * 2901 * @since 3.1.0 2902 * 2903 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. 2904 * @return bool 2905 */ 2906 function is_category( $category = '' ) { 2907 if ( !$this->is_category ) 2908 return false; 2909 2910 if ( empty($category) ) 2911 return true; 2912 2913 $cat_obj = $this->get_queried_object(); 2914 2915 $category = (array) $category; 2916 2917 if ( in_array( $cat_obj->term_id, $category ) ) 2918 return true; 2919 elseif ( in_array( $cat_obj->name, $category ) ) 2920 return true; 2921 elseif ( in_array( $cat_obj->slug, $category ) ) 2922 return true; 2923 2924 return false; 2925 } 2926 2927 /** 2928 * Is the query for a tag archive page? 2929 * 2930 * If the $tag parameter is specified, this function will additionally 2931 * check if the query is for one of the tags specified. 2932 * 2933 * @since 3.1.0 2934 * 2935 * @param mixed $slug Optional. Tag slug or array of slugs. 2936 * @return bool 2937 */ 2938 function is_tag( $slug = '' ) { 2939 if ( !$this->is_tag ) 2940 return false; 2941 2942 if ( empty( $slug ) ) 2943 return true; 2944 2945 $tag_obj = $this->get_queried_object(); 2946 2947 $slug = (array) $slug; 2948 2949 if ( in_array( $tag_obj->slug, $slug ) ) 2950 return true; 2951 2952 return false; 2953 } 2954 2955 /** 2956 * Is the query for a taxonomy archive page? 2957 * 2958 * If the $taxonomy parameter is specified, this function will additionally 2959 * check if the query is for that specific $taxonomy. 2960 * 2961 * If the $term parameter is specified in addition to the $taxonomy parameter, 2962 * this function will additionally check if the query is for one of the terms 2963 * specified. 2964 * 2965 * @since 3.1.0 2966 * 2967 * @param mixed $taxonomy Optional. Taxonomy slug or slugs. 2968 * @param mixed $term. Optional. Term ID, name, slug or array of Term IDs, names, and slugs. 2969 * @return bool 2970 */ 2971 function is_tax( $taxonomy = '', $term = '' ) { 2972 global $wp_taxonomies; 2973 2974 if ( !$this->is_tax ) 2975 return false; 2976 2977 if ( empty( $taxonomy ) ) 2978 return true; 2979 2980 $queried_object = $this->get_queried_object(); 2981 $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); 2982 $term_array = (array) $term; 2983 2984 if ( empty( $term ) ) // Only a Taxonomy provided 2985 return isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ); 2986 2987 return isset( $queried_object->term_id ) && 2988 count( array_intersect( 2989 array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), 2990 $term_array 2991 ) ); 2992 } 2993 2994 /** 2995 * Whether the current URL is within the comments popup window. 2996 * 2997 * @since 3.1.0 2998 * 2999 * @return bool 3000 */ 3001 function is_comments_popup() { 3002 return (bool) $this->is_comments_popup; 3003 } 3004 3005 /** 3006 * Is the query for a date archive? 3007 * 3008 * @since 3.1.0 3009 * 3010 * @return bool 3011 */ 3012 function is_date() { 3013 return (bool) $this->is_date; 3014 } 3015 3016 3017 /** 3018 * Is the query for a day archive? 3019 * 3020 * @since 3.1.0 3021 * 3022 * @return bool 3023 */ 3024 function is_day() { 3025 return (bool) $this->is_day; 3026 } 3027 3028 /** 3029 * Is the query for a feed? 3030 * 3031 * @since 3.1.0 3032 * 3033 * @return bool 3034 */ 3035 function is_feed() { 3036 return (bool) $this->is_feed; 3037 } 3038 3039 /** 3040 * Is the query for a comments feed? 3041 * 3042 * @since 3.1.0 3043 * 3044 * @return bool 3045 */ 3046 function is_comment_feed() { 3047 return (bool) $this->is_comment_feed; 3048 } 3049 3050 /** 3051 * Is the query for the front page of the site? 3052 * 3053 * This is for what is displayed at your site's main URL. 3054 * 3055 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. 3056 * 3057 * If you set a static page for the front page of your site, this function will return 3058 * true when viewing that page. 3059 * 3060 * Otherwise the same as @see WP_Query::is_home() 3061 * 3062 * @since 3.1.0 3063 * @uses is_home() 3064 * @uses get_option() 3065 * 3066 * @return bool True, if front of site. 3067 */ 3068 function is_front_page() { 3069 // most likely case 3070 if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) 3071 return true; 3072 elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) 3073 return true; 3074 else 3075 return false; 3076 } 3077 3078 /** 3079 * Is the query for the blog homepage? 3080 * 3081 * This is the page which shows the time based blog content of your site. 3082 * 3083 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. 3084 * 3085 * If you set a static page for the front page of your site, this function will return 3086 * true only on the page you set as the "Posts page". 3087 * 3088 * @see WP_Query::is_front_page() 3089 * 3090 * @since 3.1.0 3091 * 3092 * @return bool True if blog view homepage. 3093 */ 3094 function is_home() { 3095 return (bool) $this->is_home; 3096 } 3097 3098 /** 3099 * Is the query for a month archive? 3100 * 3101 * @since 3.1.0 3102 * 3103 * @return bool 3104 */ 3105 function is_month() { 3106 return (bool) $this->is_month; 3107 } 3108 3109 /** 3110 * Is the query for a single Page? 3111 * 3112 * If the $page parameter is specified, this function will additionally 3113 * check if the query is for one of the Pages specified. 3114 * 3115 * @see WP_Query::is_single() 3116 * @see WP_Query::is_singular() 3117 * 3118 * @since 3.1.0 3119 * 3120 * @param mixed $page Page ID, title, slug, or array of Page IDs, titles, and slugs. 3121 * @return bool 3122 */ 3123 function is_page( $page = '' ) { 3124 if ( !$this->is_page ) 3125 return false; 3126 3127 if ( empty( $page ) ) 3128 return true; 3129 3130 $page_obj = $this->get_queried_object(); 3131 3132 $page = (array) $page; 3133 3134 if ( in_array( $page_obj->ID, $page ) ) 3135 return true; 3136 elseif ( in_array( $page_obj->post_title, $page ) ) 3137 return true; 3138 else if ( in_array( $page_obj->post_name, $page ) ) 3139 return true; 3140 3141 return false; 3142 } 3143 3144 /** 3145 * Is the query for paged result and not for the first page? 3146 * 3147 * @since 3.1.0 3148 * 3149 * @return bool 3150 */ 3151 function is_paged() { 3152 return (bool) $this->is_paged; 3153 } 3154 3155 /** 3156 * Is the query for a post or page preview? 3157 * 3158 * @since 3.1.0 3159 * 3160 * @return bool 3161 */ 3162 function is_preview() { 3163 return (bool) $this->is_preview; 3164 } 3165 3166 /** 3167 * Is the query for the robots file? 3168 * 3169 * @since 3.1.0 3170 * 3171 * @return bool 3172 */ 3173 function is_robots() { 3174 return (bool) $this->is_robots; 3175 } 3176 3177 /** 3178 * Is the query for a search? 3179 * 3180 * @since 3.1.0 3181 * 3182 * @return bool 3183 */ 3184 function is_search() { 3185 return (bool) $this->is_search; 3186 } 3187 3188 /** 3189 * Is the query for a single post? 3190 * 3191 * If the $post parameter is specified, this function will additionally 3192 * check if the query is for one of the Posts specified. 3193 * 3194 * Can also be used for attachments or any other post type except pages. 3195 * 3196 * @see WP_Query::is_page() 3197 * @see WP_Query::is_singular() 3198 * 3199 * @since 3.1.0 3200 * 3201 * @param mixed $post Post ID, title, slug, or array of Post IDs, titles, and slugs. 3202 * @return bool 3203 */ 3204 function is_single( $post = '' ) { 3205 if ( !$this->is_single ) 3206 return false; 3207 3208 if ( empty($post) ) 3209 return true; 3210 3211 $post_obj = $this->get_queried_object(); 3212 3213 $post = (array) $post; 3214 3215 if ( in_array( $post_obj->ID, $post ) ) 3216 return true; 3217 elseif ( in_array( $post_obj->post_title, $post ) ) 3218 return true; 3219 elseif ( in_array( $post_obj->post_name, $post ) ) 3220 return true; 3221 3222 return false; 3223 } 3224 3225 /** 3226 * Is the query for a single post of any post type (post, attachment, page, ... )? 3227 * 3228 * If the $post_types parameter is specified, this function will additionally 3229 * check if the query is for one of the Posts Types specified. 3230 * 3231 * @see WP_Query::is_page() 3232 * @see WP_Query::is_single() 3233 * 3234 * @since 3.1.0 3235 * 3236 * @param mixed $post_types Optional. Post Type or array of Post Types 3237 * @return bool 3238 */ 3239 function is_singular( $post_types = '' ) { 3240 if ( empty( $post_types ) || !$this->is_singular ) 3241 return (bool) $this->is_singular; 3242 3243 $post_obj = $this->get_queried_object(); 3244 3245 return in_array( $post_obj->post_type, (array) $post_types ); 3246 } 3247 3248 /** 3249 * Is the query for a specific time? 3250 * 3251 * @since 3.1.0 3252 * 3253 * @return bool 3254 */ 3255 function is_time() { 3256 return (bool) $this->is_time; 3257 } 3258 3259 /** 3260 * Is the query for a trackback endpoint call? 3261 * 3262 * @since 3.1.0 3263 * 3264 * @return bool 3265 */ 3266 function is_trackback() { 3267 return (bool) $this->is_trackback; 3268 } 3269 3270 /** 3271 * Is the query for a specific year? 3272 * 3273 * @since 3.1.0 3274 * 3275 * @return bool 3276 */ 3277 function is_year() { 3278 return (bool) $this->is_year; 3279 } 3280 3281 /** 3282 * Is the query a 404 (returns no results)? 3283 * 3284 * @since 3.1.0 3285 * 3286 * @return bool 3287 */ 3288 function is_404() { 3289 return (bool) $this->is_404; 3290 } 2794 3291 } 2795 3292 2796 3293 /** … … 2809 3306 if ( is_404() && '' != $wp_query->query_vars['name'] ) : 2810 3307 global $wpdb; 2811 3308 2812 $query = "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND meta_key = '_wp_old_slug' AND meta_value='" . $wp_query->query_vars['name'] . "'"; 3309 // Guess the current post_type based on the query vars. 3310 if ( get_query_var('post_type') ) 3311 $post_type = get_query_var('post_type'); 3312 elseif ( !empty($wp_query->query_vars['pagename']) ) 3313 $post_type = 'page'; 3314 else 3315 $post_type = 'post'; 2813 3316 3317 $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']); 3318 2814 3319 // if year, monthnum, or day have been specified, make our query more precise 2815 3320 // just in case there are multiple identical _wp_old_slug values 2816 3321 if ( '' != $wp_query->query_vars['year'] ) 2817 $query .= " AND YEAR(post_date) = '{$wp_query->query_vars['year']}'";3322 $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); 2818 3323 if ( '' != $wp_query->query_vars['monthnum'] ) 2819 $query .= " AND MONTH(post_date) = '{$wp_query->query_vars['monthnum']}'";3324 $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); 2820 3325 if ( '' != $wp_query->query_vars['day'] ) 2821 $query .= " AND DAYOFMONTH(post_date) = '{$wp_query->query_vars['day']}'";3326 $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); 2822 3327 2823 3328 $id = (int) $wpdb->get_var($query); 2824 3329 2825 if ( ! $id )3330 if ( ! $id ) 2826 3331 return; 2827 3332 2828 3333 $link = get_permalink($id); … … 2845 3350 * @return bool True when finished. 2846 3351 */ 2847 3352 function setup_postdata($post) { 2848 global $id, $authordata, $ day, $currentmonth, $page, $pages, $multipage, $more, $numpages;3353 global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; 2849 3354 2850 3355 $id = (int) $post->ID; 2851 3356 2852 3357 $authordata = get_userdata($post->post_author); 2853 3358 2854 $ day = mysql2date('d.m.y', $post->post_date, false);3359 $currentday = mysql2date('d.m.y', $post->post_date, false); 2855 3360 $currentmonth = mysql2date('m', $post->post_date, false); 2856 3361 $numpages = 1; 2857 3362 $page = get_query_var('page');