Ticket #12891: query.php.r15471.diff
File query.php.r15471.diff, 42.4 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 } … … 1246 1240 function parse_query($query) { 1247 1241 if ( !empty($query) || !isset($this->query) ) { 1248 1242 $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; 1243 $this->query = $this->query_vars = wp_parse_args($query); 1254 1244 } 1255 1245 1256 1246 $this->query_vars = $this->fill_query_vars($this->query_vars); … … 1296 1286 } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) { 1297 1287 $this->is_page = true; 1298 1288 $this->is_single = false; 1299 } elseif ( !empty($qv['s']) ) {1300 $this->is_search = true;1301 1289 } else { 1302 // Look for archive queries. Dates, categories, authors .1290 // Look for archive queries. Dates, categories, authors, search, post type archives. 1303 1291 1292 if ( !empty($qv['s']) ) { 1293 $this->is_search = true; 1294 } 1295 1304 1296 if ( '' !== $qv['second'] ) { 1305 1297 $this->is_time = true; 1306 1298 $this->is_date = true; … … 1354 1346 $this->is_date = true; 1355 1347 } 1356 1348 1357 if ( empty($qv['cat']) || ($qv['cat'] == '0') ) {1349 if ( empty($qv['cat']) || ($qv['cat'] == '0') ) 1358 1350 $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 } 1351 else 1352 $this->is_category = strpos($qv['cat'], '-') === false; 1366 1353 1367 if ( '' != $qv['category_name']) {1354 if ( !empty($qv['category_name']) ) { 1368 1355 $this->is_category = true; 1369 1356 } 1370 1357 1371 if ( !is_array($qv['category__in']) ||empty($qv['category__in']) ) {1358 if ( empty($qv['category__in']) ) { 1372 1359 $qv['category__in'] = array(); 1373 1360 } else { 1374 $qv['category__in'] = array_map('absint', $qv['category__in']);1361 $qv['category__in'] = array_map('absint', (array) $qv['category__in']); 1375 1362 $this->is_category = true; 1376 1363 } 1377 1364 1378 if ( !is_array($qv['category__not_in']) ||empty($qv['category__not_in']) ) {1365 if ( empty($qv['category__not_in']) ) { 1379 1366 $qv['category__not_in'] = array(); 1380 1367 } else { 1381 $qv['category__not_in'] = array_map('absint', $qv['category__not_in']);1368 $qv['category__not_in'] = array_map('absint', (array) $qv['category__not_in']); 1382 1369 } 1383 1370 1384 if ( !is_array($qv['category__and']) ||empty($qv['category__and']) ) {1371 if ( empty($qv['category__and']) ) { 1385 1372 $qv['category__and'] = array(); 1386 1373 } else { 1387 $qv['category__and'] = array_map('absint', $qv['category__and']);1374 $qv['category__and'] = array_map('absint', (array) $qv['category__and']); 1388 1375 $this->is_category = true; 1389 1376 } 1390 1377 … … 1392 1379 $this->is_tag = true; 1393 1380 1394 1381 $qv['tag_id'] = absint($qv['tag_id']); 1395 if ( 1382 if ( !empty($qv['tag_id']) ) 1396 1383 $this->is_tag = true; 1397 1384 1398 if ( !is_array($qv['tag__in']) ||empty($qv['tag__in']) ) {1385 if ( empty($qv['tag__in']) ) { 1399 1386 $qv['tag__in'] = array(); 1400 1387 } else { 1401 $qv['tag__in'] = array_map('absint', $qv['tag__in']);1388 $qv['tag__in'] = array_map('absint', (array) $qv['tag__in']); 1402 1389 $this->is_tag = true; 1403 1390 } 1404 1391 1405 if ( !is_array($qv['tag__not_in']) ||empty($qv['tag__not_in']) ) {1392 if ( empty($qv['tag__not_in']) ) { 1406 1393 $qv['tag__not_in'] = array(); 1407 1394 } else { 1408 $qv['tag__not_in'] = array_map('absint', $qv['tag__not_in']);1395 $qv['tag__not_in'] = array_map('absint', (array) $qv['tag__not_in']); 1409 1396 } 1410 1397 1411 1398 if ( !is_array($qv['tag__and']) || empty($qv['tag__and']) ) { 1412 1399 $qv['tag__and'] = array(); 1413 1400 } else { 1414 $qv['tag__and'] = array_map('absint', $qv['tag__and']);1415 $this->is_ category= true;1401 $qv['tag__and'] = array_map('absint', (array) $qv['tag__and']); 1402 $this->is_tag = true; 1416 1403 } 1417 1404 1418 if ( !is_array($qv['tag_slug__in']) ||empty($qv['tag_slug__in']) ) {1405 if ( empty($qv['tag_slug__in']) ) { 1419 1406 $qv['tag_slug__in'] = array(); 1420 1407 } else { 1421 $qv['tag_slug__in'] = array_map('sanitize_title', $qv['tag_slug__in']);1408 $qv['tag_slug__in'] = array_map('sanitize_title', (array) $qv['tag_slug__in']); 1422 1409 $this->is_tag = true; 1423 1410 } 1424 1411 1425 if ( !is_array($qv['tag_slug__and']) ||empty($qv['tag_slug__and']) ) {1412 if ( empty($qv['tag_slug__and']) ) { 1426 1413 $qv['tag_slug__and'] = array(); 1427 1414 } else { 1428 $qv['tag_slug__and'] = array_map('sanitize_title', $qv['tag_slug__and']);1415 $qv['tag_slug__and'] = array_map('sanitize_title', (array) $qv['tag_slug__and']); 1429 1416 $this->is_tag = true; 1430 1417 } 1431 1418 … … 1449 1436 $this->is_author = true; 1450 1437 } 1451 1438 1452 if ( '' != $qv['author_name'] ) {1439 if ( '' != $qv['author_name'] ) 1453 1440 $this->is_author = true; 1441 1442 if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) { 1443 $post_type_obj = get_post_type_object( $qv['post_type'] ); 1444 if ( ! empty( $post_type_obj->has_archive ) ) 1445 $this->is_post_type_archive = true; 1454 1446 } 1455 1447 1456 if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax))1448 if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) 1457 1449 $this->is_archive = true; 1458 1450 } 1459 1451 … … 1528 1520 1529 1521 if ( !empty($qv['post_type']) ) { 1530 1522 if ( is_array($qv['post_type']) ) 1531 $qv['post_type'] = array_map('sanitize_ user', $qv['post_type'], array(true));1523 $qv['post_type'] = array_map('sanitize_key', $qv['post_type']); 1532 1524 else 1533 $qv['post_type'] = sanitize_ user($qv['post_type'], true);1525 $qv['post_type'] = sanitize_key($qv['post_type']); 1534 1526 } 1535 1527 1536 1528 if ( !empty($qv['post_status']) ) … … 1629 1621 $post_status_join = false; 1630 1622 $page = 1; 1631 1623 1632 if ( !isset($q['caller_get_posts']) ) 1633 $q['caller_get_posts'] = false; 1624 if ( isset( $q['caller_get_posts'] ) ) { 1625 _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) ); 1626 if ( !isset( $q['ignore_sticky_posts'] ) ) 1627 $q['ignore_sticky_posts'] = $q['caller_get_posts']; 1628 } 1634 1629 1630 if ( !isset( $q['ignore_sticky_posts'] ) ) 1631 $q['ignore_sticky_posts'] = false; 1632 1635 1633 if ( !isset($q['suppress_filters']) ) 1636 1634 $q['suppress_filters'] = false; 1637 1635 … … 1757 1755 } 1758 1756 1759 1757 if ( '' != $q['name'] ) { 1760 $q['name'] = sanitize_title ($q['name']);1758 $q['name'] = sanitize_title_for_query( $q['name'] ); 1761 1759 $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'"; 1762 1760 } elseif ( '' != $q['pagename'] ) { 1763 1761 if ( isset($this->queried_object_id) ) { … … 1785 1783 1786 1784 $page_for_posts = get_option('page_for_posts'); 1787 1785 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)); 1786 $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); 1791 1787 $q['name'] = $q['pagename']; 1792 1788 $where .= " AND ($wpdb->posts.ID = '$reqpage')"; 1793 1789 $reqpage_obj = get_page($reqpage); … … 1799 1795 } 1800 1796 } 1801 1797 } 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)); 1798 $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); 1805 1799 $q['name'] = $q['attachment']; 1806 1800 $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'"; 1807 1801 } … … 2102 2096 $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailling slash 2103 2097 } 2104 2098 } 2105 $q['author_name'] = sanitize_title ($q['author_name']);2099 $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); 2106 2100 $q['author'] = get_user_by('slug', $q['author_name']); 2107 2101 if ( $q['author'] ) 2108 2102 $q['author'] = $q['author']->ID; … … 2178 2172 $q['orderby'] = "$wpdb->posts.post_date ".$q['order']; 2179 2173 } 2180 2174 2181 if ( is_array( $post_type) ) {2175 if ( is_array( $post_type ) ) { 2182 2176 $post_type_cap = 'multiple_post_type'; 2183 2177 } 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 2178 $post_type_object = get_post_type_object( $post_type ); 2179 if ( empty( $post_type_object ) ) 2188 2180 $post_type_cap = $post_type; 2189 2181 } 2190 2182 … … 2211 2203 $post_type_object = get_post_type_object ( 'post' ); 2212 2204 } 2213 2205 2214 if ( !empty($post_type_object) ) { 2215 $post_type_cap = $post_type_object->capability_type; 2206 if ( ! empty( $post_type_object ) ) { 2216 2207 $edit_cap = $post_type_object->cap->edit_post; 2217 2208 $read_cap = $post_type_object->cap->read_post; 2218 2209 $edit_others_cap = $post_type_object->cap->edit_others_posts; … … 2472 2463 2473 2464 // Put sticky posts at the top of the posts array 2474 2465 $sticky_posts = get_option('sticky_posts'); 2475 if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q[' caller_get_posts'] ) {2466 if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) { 2476 2467 $num_posts = count($this->posts); 2477 2468 $sticky_offset = 0; 2478 2469 // Loop over posts and relocate stickies to the front. … … 2604 2595 2605 2596 /** 2606 2597 * Rewind the posts and reset post index. 2598 2607 2599 * 2608 2600 * @since 1.5.0 2609 2601 * @access public … … 2735 2727 if ( is_wp_error($term) || empty($term) ) 2736 2728 return NULL; 2737 2729 $term = $term[0]; 2738 $this->queried_object = $term; 2739 $this->queried_object_id = $term->term_id; 2730 if ( $term && ! is_wp_error($term) ) { 2731 $this->queried_object = $term; 2732 $this->queried_object_id = $term->term_id; 2733 } 2740 2734 } elseif ( $this->is_posts_page ) { 2741 2735 $page_for_posts = get_option('page_for_posts'); 2742 2736 $this->queried_object = & get_page( $page_for_posts ); … … 2791 2785 $this->query($query); 2792 2786 } 2793 2787 } 2788 2789 /** 2790 * Is the query for an archive page? 2791 * 2792 * Month, Year, Category, Author, Post Type archive... 2793 * 2794 * @since 3.1.0 2795 * 2796 * @return bool 2797 */ 2798 function is_archive() { 2799 return (bool) $this->is_archive; 2800 } 2801 2802 /** 2803 * Is the query for a post type archive page? 2804 * 2805 * @since 3.1.0 2806 * 2807 * @param mixed $post_types Optional. Post type or array of posts types to check against. 2808 * @return bool 2809 */ 2810 function is_post_type_archive( $post_types = '' ) { 2811 if ( empty( $post_types ) || !$this->is_post_type_archive ) 2812 return (bool) $this->is_post_type_archive; 2813 2814 if ( ! isset( $this->posts[0] ) ) 2815 return false; 2816 2817 $post = $this->posts[0]; 2818 2819 return in_array( $post->post_type, (array) $post_types ); 2820 } 2821 2822 /** 2823 * Is the query for an attachment page? 2824 * 2825 * @since 3.1.0 2826 * 2827 * @return bool 2828 */ 2829 function is_attachment() { 2830 return (bool) $this->is_attachment; 2831 } 2832 2833 /** 2834 * Is the query for an author archive page? 2835 * 2836 * If the $author parameter is specified, this function will additionally 2837 * check if the query is for one of the authors specified. 2838 * 2839 * @since 3.1.0 2840 * 2841 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames 2842 * @return bool 2843 */ 2844 function is_author( $author = '' ) { 2845 if ( !$this->is_author ) 2846 return false; 2847 2848 if ( empty($author) ) 2849 return true; 2850 2851 $author_obj = $this->get_queried_object(); 2852 2853 $author = (array) $author; 2854 2855 if ( in_array( $author_obj->ID, $author ) ) 2856 return true; 2857 elseif ( in_array( $author_obj->nickname, $author ) ) 2858 return true; 2859 elseif ( in_array( $author_obj->user_nicename, $author ) ) 2860 return true; 2861 2862 return false; 2863 } 2864 2865 /** 2866 * Is the query for a category archive page? 2867 * 2868 * If the $category parameter is specified, this function will additionally 2869 * check if the query is for one of the categories specified. 2870 * 2871 * @since 3.1.0 2872 * 2873 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. 2874 * @return bool 2875 */ 2876 function is_category( $category = '' ) { 2877 if ( !$this->is_category ) 2878 return false; 2879 2880 if ( empty($category) ) 2881 return true; 2882 2883 $cat_obj = $this->get_queried_object(); 2884 2885 $category = (array) $category; 2886 2887 if ( in_array( $cat_obj->term_id, $category ) ) 2888 return true; 2889 elseif ( in_array( $cat_obj->name, $category ) ) 2890 return true; 2891 elseif ( in_array( $cat_obj->slug, $category ) ) 2892 return true; 2893 2894 return false; 2895 } 2896 2897 /** 2898 * Is the query for a tag archive page? 2899 * 2900 * If the $tag parameter is specified, this function will additionally 2901 * check if the query is for one of the tags specified. 2902 * 2903 * @since 3.1.0 2904 * 2905 * @param mixed $slug Optional. Tag slug or array of slugs. 2906 * @return bool 2907 */ 2908 function is_tag( $slug = '' ) { 2909 if ( !$this->is_tag ) 2910 return false; 2911 2912 if ( empty( $slug ) ) 2913 return true; 2914 2915 $tag_obj = $this->get_queried_object(); 2916 2917 $slug = (array) $slug; 2918 2919 if ( in_array( $tag_obj->slug, $slug ) ) 2920 return true; 2921 2922 return false; 2923 } 2924 2925 /** 2926 * Is the query for a taxonomy archive page? 2927 * 2928 * If the $taxonomy parameter is specified, this function will additionally 2929 * check if the query is for that specific $taxonomy. 2930 * 2931 * If the $term parameter is specified in addition to the $taxonomy parameter, 2932 * this function will additionally check if the query is for one of the terms 2933 * specified. 2934 * 2935 * @since 3.1.0 2936 * 2937 * @param mixed $taxonomy Optional. Taxonomy slug or slugs. 2938 * @param mixed $term. Optional. Term ID, name, slug or array of Term IDs, names, and slugs. 2939 * @return bool 2940 */ 2941 function is_tax( $taxonomy = '', $term = '' ) { 2942 global $wp_taxonomies; 2943 2944 if ( !$this->is_tax ) 2945 return false; 2946 2947 if ( empty( $taxonomy ) ) 2948 return true; 2949 2950 $queried_object = $this->get_queried_object(); 2951 $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); 2952 $term_array = (array) $term; 2953 2954 if ( empty( $term ) ) // Only a Taxonomy provided 2955 return isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ); 2956 2957 return isset( $queried_object->term_id ) && 2958 count( array_intersect( 2959 array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), 2960 $term_array 2961 ) ); 2962 } 2963 2964 /** 2965 * Whether the current URL is within the comments popup window. 2966 * 2967 * @since 3.1.0 2968 * 2969 * @return bool 2970 */ 2971 function is_comments_popup() { 2972 return (bool) $this->is_comments_popup; 2973 } 2974 2975 /** 2976 * Is the query for a date archive? 2977 * 2978 * @since 3.1.0 2979 * 2980 * @return bool 2981 */ 2982 function is_date() { 2983 return (bool) $this->is_date; 2984 } 2985 2986 2987 /** 2988 * Is the query for a day archive? 2989 * 2990 * @since 3.1.0 2991 * 2992 * @return bool 2993 */ 2994 function is_day() { 2995 return (bool) $this->is_day; 2996 } 2997 2998 /** 2999 * Is the query for a feed? 3000 * 3001 * @since 3.1.0 3002 * 3003 * @return bool 3004 */ 3005 function is_feed() { 3006 return (bool) $this->is_feed; 3007 } 3008 3009 /** 3010 * Is the query for a comments feed? 3011 * 3012 * @since 3.1.0 3013 * 3014 * @return bool 3015 */ 3016 function is_comment_feed() { 3017 return (bool) $this->is_comment_feed; 3018 } 3019 3020 /** 3021 * Is the query for the front page of the site? 3022 * 3023 * This is for what is displayed at your site's main URL. 3024 * 3025 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. 3026 * 3027 * If you set a static page for the front page of your site, this function will return 3028 * true when viewing that page. 3029 * 3030 * Otherwise the same as @see WP_Query::is_home() 3031 * 3032 * @since 3.1.0 3033 * @uses is_home() 3034 * @uses get_option() 3035 * 3036 * @return bool True, if front of site. 3037 */ 3038 function is_front_page() { 3039 // most likely case 3040 if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) 3041 return true; 3042 elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) 3043 return true; 3044 else 3045 return false; 3046 } 3047 3048 /** 3049 * Is the query for the blog homepage? 3050 * 3051 * This is the page which shows the time based blog content of your site. 3052 * 3053 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. 3054 * 3055 * If you set a static page for the front page of your site, this function will return 3056 * true only on the page you set as the "Posts page". 3057 * 3058 * @see WP_Query::is_front_page() 3059 * 3060 * @since 3.1.0 3061 * 3062 * @return bool True if blog view homepage. 3063 */ 3064 function is_home() { 3065 return (bool) $this->is_home; 3066 } 3067 3068 /** 3069 * Is the query for a month archive? 3070 * 3071 * @since 3.1.0 3072 * 3073 * @return bool 3074 */ 3075 function is_month() { 3076 return (bool) $this->is_month; 3077 } 3078 3079 /** 3080 * Is the query for a single Page? 3081 * 3082 * If the $page parameter is specified, this function will additionally 3083 * check if the query is for one of the Pages specified. 3084 * 3085 * @see WP_Query::is_single() 3086 * @see WP_Query::is_singular() 3087 * 3088 * @since 3.1.0 3089 * 3090 * @param mixed $page Page ID, title, slug, or array of Page IDs, titles, and slugs. 3091 * @return bool 3092 */ 3093 function is_page( $page = '' ) { 3094 if ( !$this->is_page ) 3095 return false; 3096 3097 if ( empty( $page ) ) 3098 return true; 3099 3100 $page_obj = $this->get_queried_object(); 3101 3102 $page = (array) $page; 3103 3104 if ( in_array( $page_obj->ID, $page ) ) 3105 return true; 3106 elseif ( in_array( $page_obj->post_title, $page ) ) 3107 return true; 3108 else if ( in_array( $page_obj->post_name, $page ) ) 3109 return true; 3110 3111 return false; 3112 } 3113 3114 /** 3115 * Is the query for paged result and not for the first page? 3116 * 3117 * @since 3.1.0 3118 * 3119 * @return bool 3120 */ 3121 function is_paged() { 3122 return (bool) $this->is_paged; 3123 } 3124 3125 /** 3126 * Is the query for a post or page preview? 3127 * 3128 * @since 3.1.0 3129 * 3130 * @return bool 3131 */ 3132 function is_preview() { 3133 return (bool) $this->is_preview; 3134 } 3135 3136 /** 3137 * Is the query for the robots file? 3138 * 3139 * @since 3.1.0 3140 * 3141 * @return bool 3142 */ 3143 function is_robots() { 3144 return (bool) $this->is_robots; 3145 } 3146 3147 /** 3148 * Is the query for a search? 3149 * 3150 * @since 3.1.0 3151 * 3152 * @return bool 3153 */ 3154 function is_search() { 3155 return (bool) $this->is_search; 3156 } 3157 3158 /** 3159 * Is the query for a single post? 3160 * 3161 * If the $post parameter is specified, this function will additionally 3162 * check if the query is for one of the Posts specified. 3163 * 3164 * Can also be used for attachments or any other post type except pages. 3165 * 3166 * @see WP_Query::is_page() 3167 * @see WP_Query::is_singular() 3168 * 3169 * @since 3.1.0 3170 * 3171 * @param mixed $post Post ID, title, slug, or array of Post IDs, titles, and slugs. 3172 * @return bool 3173 */ 3174 function is_single( $post = '' ) { 3175 if ( !$this->is_single ) 3176 return false; 3177 3178 if ( empty($post) ) 3179 return true; 3180 3181 $post_obj = $this->get_queried_object(); 3182 3183 $post = (array) $post; 3184 3185 if ( in_array( $post_obj->ID, $post ) ) 3186 return true; 3187 elseif ( in_array( $post_obj->post_title, $post ) ) 3188 return true; 3189 elseif ( in_array( $post_obj->post_name, $post ) ) 3190 return true; 3191 3192 return false; 3193 } 3194 3195 /** 3196 * Is the query for a single post of any post type (post, attachment, page, ... )? 3197 * 3198 * If the $post_types parameter is specified, this function will additionally 3199 * check if the query is for one of the Posts Types specified. 3200 * 3201 * @see WP_Query::is_page() 3202 * @see WP_Query::is_single() 3203 * 3204 * @since 3.1.0 3205 * 3206 * @param mixed $post_types Optional. Post Type or array of Post Types 3207 * @return bool 3208 */ 3209 function is_singular( $post_types = '' ) { 3210 if ( empty( $post_types ) || !$this->is_singular ) 3211 return (bool) $this->is_singular; 3212 3213 $post_obj = $this->get_queried_object(); 3214 3215 return in_array( $post_obj->post_type, (array) $post_types ); 3216 } 3217 3218 /** 3219 * Is the query for a specific time? 3220 * 3221 * @since 3.1.0 3222 * 3223 * @return bool 3224 */ 3225 function is_time() { 3226 return (bool) $this->is_time; 3227 } 3228 3229 /** 3230 * Is the query for a trackback endpoint call? 3231 * 3232 * @since 3.1.0 3233 * 3234 * @return bool 3235 */ 3236 function is_trackback() { 3237 return (bool) $this->is_trackback; 3238 } 3239 3240 /** 3241 * Is the query for a specific year? 3242 * 3243 * @since 3.1.0 3244 * 3245 * @return bool 3246 */ 3247 function is_year() { 3248 return (bool) $this->is_year; 3249 } 3250 3251 /** 3252 * Is the query a 404 (returns no results)? 3253 * 3254 * @since 3.1.0 3255 * 3256 * @return bool 3257 */ 3258 function is_404() { 3259 return (bool) $this->is_404; 3260 } 2794 3261 } 2795 3262 2796 3263 /** … … 2809 3276 if ( is_404() && '' != $wp_query->query_vars['name'] ) : 2810 3277 global $wpdb; 2811 3278 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'] . "'"; 3279 // Guess the current post_type based on the query vars. 3280 if ( get_query_var('post_type') ) 3281 $post_type = get_query_var('post_type'); 3282 elseif ( !empty($wp_query->query_vars['pagename']) ) 3283 $post_type = 'page'; 3284 else 3285 $post_type = 'post'; 2813 3286 3287 $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']); 3288 2814 3289 // if year, monthnum, or day have been specified, make our query more precise 2815 3290 // just in case there are multiple identical _wp_old_slug values 2816 3291 if ( '' != $wp_query->query_vars['year'] ) 2817 $query .= " AND YEAR(post_date) = '{$wp_query->query_vars['year']}'";3292 $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); 2818 3293 if ( '' != $wp_query->query_vars['monthnum'] ) 2819 $query .= " AND MONTH(post_date) = '{$wp_query->query_vars['monthnum']}'";3294 $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); 2820 3295 if ( '' != $wp_query->query_vars['day'] ) 2821 $query .= " AND DAYOFMONTH(post_date) = '{$wp_query->query_vars['day']}'";3296 $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); 2822 3297 2823 3298 $id = (int) $wpdb->get_var($query); 2824 3299 2825 if ( ! $id )3300 if ( ! $id ) 2826 3301 return; 2827 3302 2828 3303 $link = get_permalink($id); … … 2845 3320 * @return bool True when finished. 2846 3321 */ 2847 3322 function setup_postdata($post) { 2848 global $id, $authordata, $ day, $currentmonth, $page, $pages, $multipage, $more, $numpages;3323 global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; 2849 3324 2850 3325 $id = (int) $post->ID; 2851 3326 2852 3327 $authordata = get_userdata($post->post_author); 2853 3328 2854 $ day = mysql2date('d.m.y', $post->post_date, false);3329 $currentday = mysql2date('d.m.y', $post->post_date, false); 2855 3330 $currentmonth = mysql2date('m', $post->post_date, false); 2856 3331 $numpages = 1; 2857 3332 $page = get_query_var('page');