2514 | | $where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) ); |
2515 | | $groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) ); |
2516 | | $join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) ); |
2517 | | $orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) ); |
2518 | | $distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) ); |
2519 | | $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) ); |
2520 | | $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) ); |
| 2530 | $where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this, false ) ); |
| 2531 | $groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this, false ) ); |
| 2532 | $join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this, false ) ); |
| 2533 | $orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this, false ) ); |
| 2534 | $distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this, false ) ); |
| 2535 | $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this, false ) ); |
| 2536 | $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this, false ) ); |
| 2538 | $quick_where = apply_filters_ref_array( 'posts_where_paged', array( $quick_where, &$this, true ) ); |
| 2539 | $quick_groupby = apply_filters_ref_array( 'posts_groupby', array( $quick_groupby, &$this, true ) ); |
| 2540 | $quick_join = apply_filters_ref_array( 'posts_join_paged', array( $quick_join, &$this, true ) ); |
| 2541 | $quick_orderby = apply_filters_ref_array( 'posts_orderby', array( $quick_orderby, &$this, true ) ); |
| 2542 | $quick_distinct = apply_filters_ref_array( 'posts_distinct', array( $quick_distinct, &$this, true ) ); |
| 2543 | $quick_limits = apply_filters_ref_array( 'post_limits', array( $quick_limits, &$this, true ) ); |
| 2544 | $quick_fields = apply_filters_ref_array( 'posts_fields', array( $quick_fields, &$this, true ) ); |
| 2545 | |
2533 | | $where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) ); |
2534 | | $groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) ); |
2535 | | $join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) ); |
2536 | | $orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) ); |
2537 | | $distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) ); |
2538 | | $fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) ); |
2539 | | $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) ); |
| 2557 | $where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this, false ) ); |
| 2558 | $groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this, false ) ); |
| 2559 | $join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this, false ) ); |
| 2560 | $orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this, false ) ); |
| 2561 | $distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this, false ) ); |
| 2562 | $fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this, false ) ); |
| 2563 | $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this, false ) ); |
| 2565 | $quick_where = apply_filters_ref_array( 'posts_where_request', array( $quick_where, &$this, true ) ); |
| 2566 | $quick_groupby = apply_filters_ref_array( 'posts_groupby_request', array( $quick_groupby, &$this, true ) ); |
| 2567 | $quick_join = apply_filters_ref_array( 'posts_join_request', array( $quick_join, &$this, true ) ); |
| 2568 | $quick_orderby = apply_filters_ref_array( 'posts_orderby_request', array( $quick_orderby, &$this, true ) ); |
| 2569 | $quick_distinct = apply_filters_ref_array( 'posts_distinct_request', array( $quick_distinct, &$this, true ) ); |
| 2570 | $quick_fields = apply_filters_ref_array( 'posts_fields_request', array( $quick_fields, &$this, true ) ); |
| 2571 | $quick_limits = apply_filters_ref_array( 'post_limits_request', array( $quick_limits, &$this, true ) ); |
| 2572 | |
2556 | | $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
2557 | | if ( !$q['suppress_filters'] ) |
2558 | | $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); |
| 2590 | if ( empty($limits) ) { |
| 2591 | // Do a direct query, as there is no benefit in fetching a huge load of IDs in an IN clause |
| 2592 | $this->request = " SELECT $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby"; |
| 2593 | $this->quick_request = " SELECT $quick_distinct $quick_fields FROM $wpdb->posts $quick_join WHERE 1=1 $quick_where $quick_groupby $orderby"; |
2573 | | return $r; |
| 2608 | return $r; |
| 2609 | } |
| 2610 | |
| 2611 | if ( !$q['suppress_filters'] ) { |
| 2612 | $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this, false ) ); |
| 2613 | $this->quick_request = apply_filters_ref_array( 'posts_request', array( $this->quick_request, &$this, true ) ); |
| 2614 | } |
| 2615 | |
| 2616 | $this->posts = $wpdb->get_results($this->quick_request); |
| 2617 | |
| 2618 | $this->found_posts = count($this->posts); |
| 2619 | $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); |
| 2620 | $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); |
| 2621 | } else { |
| 2622 | $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
| 2623 | if ( !$q['suppress_filters'] ) |
| 2624 | $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this, false ) ); |
| 2625 | |
| 2626 | $post_ids = $wpdb->get_col($this->request); |
| 2627 | |
| 2628 | if ( empty($post_ids) ) { |
| 2629 | $this->found_posts = 0; |
| 2630 | $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); |
| 2631 | $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); |
| 2632 | |
| 2633 | $this->quick_request = " SELECT $quick_distinct $quick_fields FROM $wpdb->posts $quick_join WHERE 1=1 $quick_where $quick_groupby $orderby"; |
| 2634 | if ( !$q['suppress_filters'] ) |
| 2635 | $this->quick_request = apply_filters_ref_array('posts_request', array( $this->quick_request, &$this, true ) ); |
| 2636 | |
| 2637 | $this->posts = array(); // no point in querying, since there are no posts |
| 2638 | } else { |
| 2639 | $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); |
| 2640 | $this->found_posts = $wpdb->get_var( $found_posts_query ); |
| 2641 | $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); |
| 2642 | $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); |
| 2643 | |
| 2644 | $post_ids = implode(',', $post_ids); |
| 2645 | $this->quick_request = " SELECT $quick_distinct $quick_fields FROM $wpdb->posts $quick_join WHERE 1 = 1 $quick_where AND $wpdb->posts.ID IN ($post_ids) $quick_groupby ORDER BY FIELD( $wpdb->posts.ID, $post_ids ) "; |
| 2646 | |
| 2647 | if ( !$q['suppress_filters'] ) |
| 2648 | $this->quick_request = apply_filters_ref_array( 'posts_request', array( $this->quick_request, &$this, true ) ); |
| 2649 | |
| 2650 | $this->posts = $wpdb->get_results($this->quick_request); |
| 2651 | } |