Changeset 19918 for trunk/wp-includes/query.php
- Timestamp:
- 02/14/2012 03:09:35 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/query.php
r19866 r19918 2607 2607 $found_rows = 'SQL_CALC_FOUND_ROWS'; 2608 2608 2609 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2610 if ( !$q['suppress_filters'] ) 2611 $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); 2609 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2610 2611 if ( !$q['suppress_filters'] ) { 2612 $this->request = apply_filters( 'posts_request', $this->request, $this ); 2613 } 2612 2614 2613 2615 if ( 'ids' == $q['fields'] ) { … … 2627 2629 } 2628 2630 2629 $this->posts = $wpdb->get_results($this->request); 2631 if ( $old_request == $this->request && "$wpdb->posts.*" == $fields ) { 2632 // First get the IDs and then fill in the objects 2633 2634 $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2635 2636 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 2637 2638 $ids = $wpdb->get_col( $this->request ); 2639 2640 if ( $ids ) { 2641 $this->set_found_posts( $q, $limits ); 2642 2643 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 2644 2645 $this->posts = array_map( 'get_post', $ids ); 2646 } else { 2647 $this->found_posts = $this->max_num_pages = 0; 2648 $this->posts = array(); 2649 } 2650 } else { 2651 $this->posts = $wpdb->get_results( $this->request ); 2652 $this->set_found_posts( $q, $limits ); 2653 } 2630 2654 2631 2655 // Raw results filter. Prior to status checks. … … 2644 2668 $this->comments = $wpdb->get_results($comments_request); 2645 2669 $this->comment_count = count($this->comments); 2646 }2647 2648 if ( !$q['no_found_rows'] && !empty($limits) ) {2649 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );2650 $this->found_posts = $wpdb->get_var( $found_posts_query );2651 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );2652 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);2653 2670 } 2654 2671 … … 2755 2772 } 2756 2773 2774 function set_found_posts( $q, $limits ) { 2775 global $wpdb; 2776 2777 if ( $q['no_found_rows'] || empty( $limits ) ) 2778 return; 2779 2780 $this->found_posts = $wpdb->get_var( apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()', $this ) ); 2781 $this->found_posts = apply_filters( 'found_posts', $this->found_posts, $this ); 2782 2783 $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); 2784 } 2785 2757 2786 /** 2758 2787 * Set up the next post and iterate current post index.
Note: See TracChangeset
for help on using the changeset viewer.