Ticket #22176: 22176.patch
File 22176.patch, 7.8 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; 1737 } 1738 1739 if ( ! isset( $q['update_post_cache'] ) ) { 1740 $q['update_post_cache'] = $q['cache_results']; 1740 1741 } 1741 1742 1742 1743 if ( !isset($q['update_post_term_cache']) ) … … 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 ( $q['cache_results'] ) { 2782 global $wp_post_types; 2783 $_args = $this->query_vars; 2784 unset( $_args['field'] ); 2785 $key = md5( serialize( $_args + $wp_post_types) ); 2786 $last_changed = wp_cache_get_last_changed( 'posts' ); 2787 2788 $cache_key = "get_posts:$key:$last_changed"; 2789 $cache_value = wp_cache_get( $cache_key, 'posts' ); 2790 2791 if ( false !== $cache_value ) { 2792 $this->posts = $cache_value['post_ids']; 2793 $this->found_posts = $cache_value['found_posts']; 2786 2794 } 2787 2788 $this->posts = array_map( 'intval', $this->posts );2789 $this->post_count = count( $this->posts );2790 $this->set_found_posts( $q, $limits );2791 2792 return $this->posts;2793 2795 } 2794 2796 2795 if ( 'id=>parent' == $q['fields'] ) { 2796 if ( null === $this->posts ) { 2797 $this->posts = $wpdb->get_results( $this->request ); 2798 } 2799 2800 $this->post_count = count( $this->posts ); 2801 $this->set_found_posts( $q, $limits ); 2802 2803 $r = array(); 2804 foreach ( $this->posts as $key => $post ) { 2805 $this->posts[ $key ]->ID = (int) $post->ID; 2806 $this->posts[ $key ]->post_parent = (int) $post->post_parent; 2797 if ( null === $this->posts ) { 2807 2798 2808 $r[ (int) $post->ID ] = (int) $post->post_parent; 2799 if ( "{$wpdb->posts}.ID" == $fields ) { 2800 $split_the_query = true; 2801 } else if ( "{$wpdb->posts}.*" == $fields ) { 2802 $split_the_query = ( $old_request == $this->request && ! empty( $limits ) && $q['posts_per_page'] < 500 ); 2809 2803 } 2810 2804 2811 return $r;2812 }2813 2805 2814 if ( null === $this->posts ) {2815 $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );2816 2806 2817 2807 /** 2818 2808 * Filters whether to split the query. … … 2846 2836 $ids = $wpdb->get_col( $this->request ); 2847 2837 2848 2838 if ( $ids ) { 2849 $this->posts = $ids;2839 $this->posts = array_map( 'intval', $ids ); 2850 2840 $this->set_found_posts( $q, $limits ); 2851 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 2841 if ( 'ids' != $q['fields'] ) { 2842 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 2843 } 2852 2844 } else { 2853 2845 $this->posts = array(); 2854 2846 } … … 2858 2850 } 2859 2851 } 2860 2852 2853 if ( 'ids' == $q['fields'] ) { 2854 $this->post_count = count( $this->posts ); 2855 if ( $q['cache_results'] ) { 2856 $cache_value = array( 2857 'post_ids' => $this->posts, 2858 'found_posts' => $this->found_posts, 2859 ); 2860 wp_cache_add( $cache_key, $cache_value, 'posts' ); 2861 } 2862 2863 return $this->posts; 2864 } 2865 2861 2866 // Convert to WP_Post objects. 2862 2867 if ( $this->posts ) { 2863 2868 $this->posts = array_map( 'get_post', $this->posts ); … … 2875 2880 $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); 2876 2881 } 2877 2882 2883 if ( $q['cache_results'] && is_array( $this->posts ) ) { 2884 $post_ids = wp_list_pluck( $this->posts, 'ID' ); 2885 $cache_value = array( 2886 'post_ids' => $post_ids, 2887 'found_posts' => $this->found_posts, 2888 ); 2889 wp_cache_add( $cache_key, $cache_value, 'posts' ); 2890 } 2891 2878 2892 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { 2879 2893 /** This filter is documented in wp-includes/query.php */ 2880 2894 $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); … … 3011 3025 // of the type WP_Post and are filtered. 3012 3026 if ( $this->posts ) { 3013 3027 $this->post_count = count( $this->posts ); 3014 3015 3028 $this->posts = array_map( 'get_post', $this->posts ); 3016 3029 3017 if ( $q['cache_results'] ) 3030 // Prime post caches. 3031 if ( $q['update_post_cache'] ) { 3018 3032 update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); 3033 } 3019 3034 3020 3035 $this->post = reset( $this->posts ); 3021 3036 } else { … … 3027 3042 wp_queue_posts_for_term_meta_lazyload( $this->posts ); 3028 3043 } 3029 3044 3045 3046 if ( 'id=>parent' == $q['fields'] ) { 3047 $r = array(); 3048 foreach ( $this->posts as $key => $post ) { 3049 $this->posts[ $key ]->ID = (int) $post->ID; 3050 $this->posts[ $key ]->post_parent = (int) $post->post_parent; 3051 3052 $r[ (int) $post->ID ] = (int) $post->post_parent; 3053 } 3054 3055 return $r; 3056 } 3057 3030 3058 return $this->posts; 3031 3059 } 3032 3060 … … 3406 3434 } 3407 3435 3408 3436 /** 3409 3410 3411 3412 * 3413 3414 3415 3416 3437 * Is the query for an existing archive page? 3438 * 3439 * Month, Year, Category, Author, Post Type archive... 3440 * 3441 * @since 3.1.0 3442 * 3443 * @return bool 3444 */ 3417 3445 public function is_archive() { 3418 3446 return (bool) $this->is_archive; 3419 3447 } … … 3605 3633 return true; 3606 3634 3607 3635 return isset( $queried_object->term_id ) && 3608 3609 3610 3611 3636 count( array_intersect( 3637 array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), 3638 $term_array 3639 ) ); 3612 3640 } 3613 3641 3614 3642 /** … … 4055 4083 } 4056 4084 $multipage = 1; 4057 4085 } else { 4058 4059 4086 $multipage = 0; 4087 } 4060 4088 4061 4089 /** 4062 4090 * Fires once the post data has been setup.