Make WordPress Core

Ticket #36687: query.php.patch

File query.php.patch, 4.6 KB (added by jpdavoutian, 7 years ago)
  • query.php

     
    35483548                        $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) );
    35493549                }
    35503550
     3551                $this->external_query = $q['external'];
     3552                if ( !isset($q['external']) || $q['external'] ) {
     3553                        $this->external_query = FALSE;
     3554                        $this->external_query = apply_filters_ref_array( 'posts_query_external', array( $this->external_query, &$this ) );
     3555                }
     3556
    35513557                if ( 'ids' == $q['fields'] ) {
    3552                         $this->posts = $wpdb->get_col( $this->request );
    3553                         $this->posts = array_map( 'intval', $this->posts );
    3554                         $this->post_count = count( $this->posts );
    3555                         $this->set_found_posts( $q, $limits );
     3558                        if ( !$this->external_query ) {
     3559                                $this->posts = $wpdb->get_col( $this->request );
     3560                                $this->posts = array_map( 'intval', $this->posts );
     3561                                $this->post_count = count( $this->posts );
     3562                                $this->set_found_posts( $q, $limits );
     3563                        }
    35563564
    35573565                        return $this->posts;
    35583566                }
    35593567
    35603568                if ( 'id=>parent' == $q['fields'] ) {
    3561                         $this->posts = $wpdb->get_results( $this->request );
    3562                         $this->post_count = count( $this->posts );
    3563                         $this->set_found_posts( $q, $limits );
     3569                        if ( !$this->external_query ) {
     3570                                $this->posts = $wpdb->get_results( $this->request );
     3571                                $this->post_count = count( $this->posts );
     3572                                $this->set_found_posts( $q, $limits );
     3573                        }
    35643574
    35653575                        $r = array();
    35663576                        foreach ( $this->posts as $key => $post ) {
     
    35733583                        return $r;
    35743584                }
    35753585
    3576                 $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
     3586                if ( !$this->external_query ) {
     3587                        $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
    35773588
    3578                 /**
    3579                  * Filter whether to split the query.
    3580                  *
    3581                  * Splitting the query will cause it to fetch just the IDs of the found posts
    3582                  * (and then individually fetch each post by ID), rather than fetching every
    3583                  * complete row at once. One massive result vs. many small results.
    3584                  *
    3585                  * @since 3.4.0
    3586                  *
    3587                  * @param bool     $split_the_query Whether or not to split the query.
    3588                  * @param WP_Query $this            The WP_Query instance.
    3589                  */
    3590                 $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
    3591 
    3592                 if ( $split_the_query ) {
    3593                         // First get the IDs and then fill in the objects
    3594 
    3595                         $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
    3596 
    35973589                        /**
    3598                          * Filter the Post IDs SQL request before sending.
     3590                         * Filter whether to split the query.
    35993591                         *
     3592                         * Splitting the query will cause it to fetch just the IDs of the found posts
     3593                         * (and then individually fetch each post by ID), rather than fetching every
     3594                         * complete row at once. One massive result vs. many small results.
     3595                         *
    36003596                         * @since 3.4.0
    36013597                         *
    3602                          * @param string   $request The post ID request.
    3603                          * @param WP_Query $this    The WP_Query instance.
     3598                         * @param bool     $split_the_query Whether or not to split the query.
     3599                         * @param WP_Query $this            The WP_Query instance.
    36043600                         */
    3605                         $this->request = apply_filters( 'posts_request_ids', $this->request, $this );
     3601                        $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
    36063602
    3607                         $ids = $wpdb->get_col( $this->request );
     3603                        if ( $split_the_query ) {
     3604                                // First get the IDs and then fill in the objects
    36083605
    3609                         if ( $ids ) {
    3610                                 $this->posts = $ids;
     3606                                $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
     3607
     3608                                /**
     3609                                 * Filter the Post IDs SQL request before sending.
     3610                                 *
     3611                                 * @since 3.4.0
     3612                                 *
     3613                                 * @param string   $request The post ID request.
     3614                                 * @param WP_Query $this    The WP_Query instance.
     3615                                 */
     3616                                $this->request = apply_filters( 'posts_request_ids', $this->request, $this );
     3617
     3618                                $ids = $wpdb->get_col( $this->request );
     3619
     3620                                if ( $ids ) {
     3621                                        $this->posts = $ids;
     3622                                        $this->set_found_posts( $q, $limits );
     3623                                        _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
     3624                                } else {
     3625                                        $this->posts = array();
     3626                                }
     3627                        } else {
     3628                                $this->posts = $wpdb->get_results( $this->request );
    36113629                                $this->set_found_posts( $q, $limits );
    3612                                 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
    3613                         } else {
    3614                                 $this->posts = array();
    36153630                        }
    3616                 } else {
    3617                         $this->posts = $wpdb->get_results( $this->request );
    3618                         $this->set_found_posts( $q, $limits );
    36193631                }
    36203632
    36213633                // Convert to WP_Post objects