Changeset 37692 for trunk/src/wp-includes/query.php
- Timestamp:
- 06/14/2016 01:59:25 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r37589 r37692 3557 3557 } 3558 3558 3559 /** 3560 * Filters the posts array before the query takes place. 3561 * 3562 * Return a non-null value to bypass WordPress's default post queries. 3563 * 3564 * Filtering functions that require pagination information are encouraged to set 3565 * the `found_posts` and `max_num_pages` properties of the WP_Query object, 3566 * passed to the filter by reference. If WP_Query does not perform a database 3567 * query, it will not have enough information to generate these values itself. 3568 * 3569 * @since 4.6.0 3570 * 3571 * @param array|null $posts Return an array of post data to short-circuit WP's query, 3572 * or null to allow WP to run its normal queries. 3573 * @param WP_Query $this The WP_Query instance, passed by reference. 3574 */ 3575 $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); 3576 3559 3577 if ( 'ids' == $q['fields'] ) { 3560 $this->posts = $wpdb->get_col( $this->request ); 3578 if ( null === $this->posts ) { 3579 $this->posts = $wpdb->get_col( $this->request ); 3580 } 3581 3561 3582 $this->posts = array_map( 'intval', $this->posts ); 3562 3583 $this->post_count = count( $this->posts ); … … 3567 3588 3568 3589 if ( 'id=>parent' == $q['fields'] ) { 3569 $this->posts = $wpdb->get_results( $this->request ); 3590 if ( null === $this->posts ) { 3591 $this->posts = $wpdb->get_results( $this->request ); 3592 } 3593 3570 3594 $this->post_count = count( $this->posts ); 3571 3595 $this->set_found_posts( $q, $limits ); … … 3582 3606 } 3583 3607 3584 $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 3585 3586 /** 3587 * Filters whether to split the query. 3588 * 3589 * Splitting the query will cause it to fetch just the IDs of the found posts 3590 * (and then individually fetch each post by ID), rather than fetching every 3591 * complete row at once. One massive result vs. many small results. 3592 * 3593 * @since 3.4.0 3594 * 3595 * @param bool $split_the_query Whether or not to split the query. 3596 * @param WP_Query $this The WP_Query instance. 3597 */ 3598 $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); 3599 3600 if ( $split_the_query ) { 3601 // First get the IDs and then fill in the objects 3602 3603 $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 3608 if ( null === $this->posts ) { 3609 $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 3604 3610 3605 3611 /** 3606 * Filters the Post IDs SQL request before sending. 3612 * Filters whether to split the query. 3613 * 3614 * Splitting the query will cause it to fetch just the IDs of the found posts 3615 * (and then individually fetch each post by ID), rather than fetching every 3616 * complete row at once. One massive result vs. many small results. 3607 3617 * 3608 3618 * @since 3.4.0 3609 3619 * 3610 * @param string $request The post ID request.3611 * @param WP_Query $this The WP_Query instance.3620 * @param bool $split_the_query Whether or not to split the query. 3621 * @param WP_Query $this The WP_Query instance. 3612 3622 */ 3613 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 3614 3615 $ids = $wpdb->get_col( $this->request ); 3616 3617 if ( $ids ) { 3618 $this->posts = $ids; 3619 $this->set_found_posts( $q, $limits ); 3620 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 3623 $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); 3624 3625 if ( $split_the_query ) { 3626 // First get the IDs and then fill in the objects 3627 3628 $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 3629 3630 /** 3631 * Filters the Post IDs SQL request before sending. 3632 * 3633 * @since 3.4.0 3634 * 3635 * @param string $request The post ID request. 3636 * @param WP_Query $this The WP_Query instance. 3637 */ 3638 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 3639 3640 $ids = $wpdb->get_col( $this->request ); 3641 3642 if ( $ids ) { 3643 $this->posts = $ids; 3644 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 3645 } else { 3646 $this->posts = array(); 3647 } 3621 3648 } else { 3622 $this->posts = array(); 3623 } 3624 } else { 3625 $this->posts = $wpdb->get_results( $this->request ); 3649 $this->posts = $wpdb->get_results( $this->request ); 3650 } 3651 } 3652 3653 // Convert to WP_Post objects and set the found-post totals. 3654 if ( $this->posts ) { 3655 $this->posts = array_map( 'get_post', $this->posts ); 3626 3656 $this->set_found_posts( $q, $limits ); 3627 3657 } 3628 3629 // Convert to WP_Post objects3630 if ( $this->posts )3631 $this->posts = array_map( 'get_post', $this->posts );3632 3658 3633 3659 if ( ! $q['suppress_filters'] ) {
Note: See TracChangeset
for help on using the changeset viewer.