Ticket #36687: query.php.patch
File query.php.patch, 4.6 KB (added by , 7 years ago) |
---|
-
query.php
3548 3548 $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) ); 3549 3549 } 3550 3550 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 3551 3557 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 } 3556 3564 3557 3565 return $this->posts; 3558 3566 } 3559 3567 3560 3568 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 } 3564 3574 3565 3575 $r = array(); 3566 3576 foreach ( $this->posts as $key => $post ) { … … 3573 3583 return $r; 3574 3584 } 3575 3585 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 ); 3577 3588 3578 /**3579 * Filter whether to split the query.3580 *3581 * Splitting the query will cause it to fetch just the IDs of the found posts3582 * (and then individually fetch each post by ID), rather than fetching every3583 * complete row at once. One massive result vs. many small results.3584 *3585 * @since 3.4.03586 *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 objects3594 3595 $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";3596 3597 3589 /** 3598 * Filter the Post IDs SQL request before sending.3590 * Filter whether to split the query. 3599 3591 * 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 * 3600 3596 * @since 3.4.0 3601 3597 * 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. 3604 3600 */ 3605 $ this->request = apply_filters( 'posts_request_ids', $this->request, $this );3601 $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); 3606 3602 3607 $ids = $wpdb->get_col( $this->request ); 3603 if ( $split_the_query ) { 3604 // First get the IDs and then fill in the objects 3608 3605 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 ); 3611 3629 $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();3615 3630 } 3616 } else {3617 $this->posts = $wpdb->get_results( $this->request );3618 $this->set_found_posts( $q, $limits );3619 3631 } 3620 3632 3621 3633 // Convert to WP_Post objects