Ticket #22176: 22176.3.patch
File 22176.3.patch, 8.0 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-query.php
472 472 * @access public 473 473 * @var bool 474 474 */ 475 475 public $thumbnails_cached = false; 476 476 477 477 /** 478 478 * Cached list of search stopwords. … … 574 574 public function fill_query_vars($array) { 575 575 $keys = array( 576 576 'error' 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 577 , 'm' 578 , 'p' 579 , 'post_parent' 580 , 'subpost' 581 , 'subpost_id' 582 , 'attachment' 583 , 'attachment_id' 584 , 'name' 585 , 'static' 586 , 'pagename' 587 , 'page_id' 588 , 'second' 589 , 'minute' 590 , 'hour' 591 , 'day' 592 , 'monthnum' 593 , 'year' 594 , 'w' 595 , 'category_name' 596 , 'tag' 597 , 'cat' 598 , 'tag_id' 599 , 'author' 600 , 'author_name' 601 , 'feed' 602 , 'tb' 603 , 'paged' 604 , 'meta_key' 605 , 'meta_value' 606 , 'preview' 607 , 's' 608 , 'sentence' 609 , 'title' 610 , 'fields' 611 , 'menu_order' 612 , 'embed' 613 613 ); 614 614 615 615 foreach ( $keys as $key ) { … … 1090 1090 'field' => 'slug', 1091 1091 ); 1092 1092 1093 1093 if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) { 1094 1094 $q[$t->query_var] = wp_basename( $q[$t->query_var] ); 1095 1095 } 1096 1096 … … 1733 1733 $q['suppress_filters'] = false; 1734 1734 1735 1735 if ( !isset($q['cache_results']) ) { 1736 if ( wp_using_ext_object_cache() ) 1737 $q['cache_results'] = false; 1738 else 1739 $q['cache_results'] = true; 1736 $q['cache_results'] = true; 1740 1737 } 1741 1738 1739 if ( ! isset( $q['update_post_cache'] ) ) { 1740 $q['update_post_cache'] = $q['cache_results']; 1741 } 1742 1742 1743 if ( !isset($q['update_post_term_cache']) ) 1743 1744 $q['update_post_term_cache'] = true; 1744 1745 … … 1812 1813 case 'ids': 1813 1814 $fields = "{$wpdb->posts}.ID"; 1814 1815 break; 1815 case 'id=>parent':1816 $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent";1817 break;1818 1816 default: 1819 1817 $fields = "{$wpdb->posts}.*"; 1820 1818 } … … 2780 2778 */ 2781 2779 $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); 2782 2780 2783 if ( 'ids' == $q['fields'] ) { 2784 if ( null === $this->posts ) { 2785 $this->posts = $wpdb->get_col( $this->request ); 2781 if ( null === $this->posts && $q['cache_results'] ) { 2782 global $wp_post_types; 2783 2784 $key = md5( serialize( $this->request + $wp_post_types ) ); 2785 $last_changed = wp_cache_get_last_changed( 'posts' ); 2786 // If there is a taxonomy query, salt the cache key with terms last changed. 2787 if ( ! empty( $q['tax_query'] ) ) { 2788 $last_changed .= wp_cache_get_last_changed( 'terms' ); 2786 2789 } 2790 $cache_key = "get_posts:$key:$last_changed"; 2791 $cache_value = wp_cache_get( $cache_key, 'posts' ); 2787 2792 2788 $this->posts = array_map( 'intval', $this->posts ); 2789 $this->post_count = count( $this->posts ); 2790 $this->set_found_posts( $q, $limits ); 2791 2792 return $this->posts; 2793 if ( false !== $cache_value ) { 2794 $this->posts = $cache_value['post_ids']; 2795 $this->found_posts = $cache_value['found_posts']; 2796 } 2793 2797 } 2794 2798 2795 if ( 'id=>parent' == $q['fields'] ) { 2796 if ( null === $this->posts ) { 2797 $this->posts = $wpdb->get_results( $this->request ); 2798 } 2799 if ( null === $this->posts ) { 2799 2800 2800 $this->post_count = count( $this->posts ); 2801 $this->set_found_posts( $q, $limits ); 2802 2803 $r = array(); 2804 foreach ( $this->posts as $key => $post ) { 2805 $this->posts[ $key ]->ID = (int) $post->ID; 2806 $this->posts[ $key ]->post_parent = (int) $post->post_parent; 2807 2808 $r[ (int) $post->ID ] = (int) $post->post_parent; 2801 if ( "{$wpdb->posts}.ID" == $fields ) { 2802 $split_the_query = true; 2803 } else if ( "{$wpdb->posts}.*" == $fields ) { 2804 $split_the_query = ( $old_request == $this->request && ! empty( $limits ) && $q['posts_per_page'] < 500 ); 2809 2805 } 2810 2806 2811 return $r;2812 }2813 2807 2814 if ( null === $this->posts ) {2815 $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );2816 2808 2817 2809 /** 2818 2810 * Filters whether to split the query. … … 2846 2838 $ids = $wpdb->get_col( $this->request ); 2847 2839 2848 2840 if ( $ids ) { 2849 $this->posts = $ids;2841 $this->posts = array_map( 'intval', $ids ); 2850 2842 $this->set_found_posts( $q, $limits ); 2851 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 2843 if ( 'ids' != $q['fields'] ) { 2844 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 2845 } 2852 2846 } else { 2853 2847 $this->posts = array(); 2854 2848 } … … 2858 2852 } 2859 2853 } 2860 2854 2855 if ( 'ids' == $q['fields'] ) { 2856 $this->post_count = count( $this->posts ); 2857 if ( $q['cache_results'] ) { 2858 $cache_value = array( 2859 'post_ids' => $this->posts, 2860 'found_posts' => $this->found_posts, 2861 ); 2862 wp_cache_add( $cache_key, $cache_value, 'posts' ); 2863 } 2864 2865 return $this->posts; 2866 } 2867 2861 2868 // Convert to WP_Post objects. 2862 2869 if ( $this->posts ) { 2863 2870 $this->posts = array_map( 'get_post', $this->posts ); … … 2875 2882 $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); 2876 2883 } 2877 2884 2885 if ( $q['cache_results'] && is_array( $this->posts ) ) { 2886 $post_ids = wp_list_pluck( $this->posts, 'ID' ); 2887 $cache_value = array( 2888 'post_ids' => $post_ids, 2889 'found_posts' => $this->found_posts, 2890 ); 2891 wp_cache_add( $cache_key, $cache_value, 'posts' ); 2892 } 2893 2878 2894 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { 2879 2895 /** This filter is documented in wp-includes/query.php */ 2880 2896 $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); … … 3011 3027 // of the type WP_Post and are filtered. 3012 3028 if ( $this->posts ) { 3013 3029 $this->post_count = count( $this->posts ); 3014 3015 3030 $this->posts = array_map( 'get_post', $this->posts ); 3016 3031 3017 if ( $q['cache_results'] ) 3032 // Prime post caches. 3033 if ( $q['update_post_cache'] ) { 3018 3034 update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); 3035 } 3019 3036 3020 3037 $this->post = reset( $this->posts ); 3021 3038 } else { … … 3027 3044 wp_queue_posts_for_term_meta_lazyload( $this->posts ); 3028 3045 } 3029 3046 3047 3048 if ( 'id=>parent' == $q['fields'] ) { 3049 $r = array(); 3050 foreach ( $this->posts as $key => $post ) { 3051 $this->posts[ $key ]->ID = (int) $post->ID; 3052 $this->posts[ $key ]->post_parent = (int) $post->post_parent; 3053 3054 $r[ (int) $post->ID ] = (int) $post->post_parent; 3055 } 3056 3057 return $r; 3058 } 3059 3030 3060 return $this->posts; 3031 3061 } 3032 3062 … … 3406 3436 } 3407 3437 3408 3438 /** 3409 * Is the query for an existing archive page? 3410 * 3411 * Month, Year, Category, Author, Post Type archive... 3439 * Is the query for an existing archive page? 3412 3440 * 3413 * @since 3.1.0 3414 * 3415 * @return bool 3416 */ 3441 * Month, Year, Category, Author, Post Type archive... 3442 * 3443 * @since 3.1.0 3444 * 3445 * @return bool 3446 */ 3417 3447 public function is_archive() { 3418 3448 return (bool) $this->is_archive; 3419 3449 } … … 3605 3635 return true; 3606 3636 3607 3637 return isset( $queried_object->term_id ) && 3608 3609 3610 3611 3638 count( array_intersect( 3639 array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), 3640 $term_array 3641 ) ); 3612 3642 } 3613 3643 3614 3644 /** … … 4055 4085 } 4056 4086 $multipage = 1; 4057 4087 } else { 4058 4059 4088 $multipage = 0; 4089 } 4060 4090 4061 4091 /** 4062 4092 * Fires once the post data has been setup.