Changeset 38768 for trunk/src/wp-includes/class-wp-query.php
- Timestamp:
- 10/10/2016 06:37:02 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r38586 r38768 486 486 487 487 private $compat_methods = array( 'init_query_flags', 'parse_tax_query' ); 488 489 /**490 * @since 4.7.0491 * @access protected492 * @var wpdb493 */494 protected $db;495 488 496 489 /** … … 1298 1291 */ 1299 1292 protected function parse_search( &$q ) { 1293 global $wpdb; 1294 1300 1295 $search = ''; 1301 1296 … … 1337 1332 1338 1333 if ( $n && $include ) { 1339 $like = '%' . $ this->db->esc_like( $term ) . '%';1340 $q['search_orderby_title'][] = $ this->db->prepare( "{$this->db->posts}.post_title LIKE %s", $like );1341 } 1342 1343 $like = $n . $ this->db->esc_like( $term ) . $n;1344 $search .= $ this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like );1334 $like = '%' . $wpdb->esc_like( $term ) . '%'; 1335 $q['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like ); 1336 } 1337 1338 $like = $n . $wpdb->esc_like( $term ) . $n; 1339 $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like ); 1345 1340 $searchand = ' AND '; 1346 1341 } … … 1349 1344 $search = " AND ({$search}) "; 1350 1345 if ( ! is_user_logged_in() ) { 1351 $search .= " AND ({$ this->db->posts}.post_password = '') ";1346 $search .= " AND ({$wpdb->posts}.post_password = '') "; 1352 1347 } 1353 1348 } … … 1437 1432 */ 1438 1433 protected function parse_search_order( &$q ) { 1434 global $wpdb; 1435 1439 1436 if ( $q['search_terms_count'] > 1 ) { 1440 1437 $num_terms = count( $q['search_orderby_title'] ); … … 1443 1440 $like = ''; 1444 1441 if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) { 1445 $like = '%' . $ this->db->esc_like( $q['s'] ) . '%';1442 $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; 1446 1443 } 1447 1444 … … 1450 1447 // sentence match in 'post_title' 1451 1448 if ( $like ) { 1452 $search_orderby .= $ this->db->prepare( "WHEN {$this->db->posts}.post_title LIKE %s THEN 1 ", $like );1449 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like ); 1453 1450 } 1454 1451 … … 1465 1462 // Sentence match in 'post_content' and 'post_excerpt'. 1466 1463 if ( $like ) { 1467 $search_orderby .= $ this->db->prepare( "WHEN {$this->db->posts}.post_excerpt LIKE %s THEN 4 ", $like );1468 $search_orderby .= $ this->db->prepare( "WHEN {$this->db->posts}.post_content LIKE %s THEN 5 ", $like );1464 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_excerpt LIKE %s THEN 4 ", $like ); 1465 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_content LIKE %s THEN 5 ", $like ); 1469 1466 } 1470 1467 … … 1491 1488 */ 1492 1489 protected function parse_orderby( $orderby ) { 1490 global $wpdb; 1491 1493 1492 // Used to filter values. 1494 1493 $allowed_keys = array( … … 1537 1536 case 'menu_order': 1538 1537 case 'comment_count': 1539 $orderby_clause = "{$ this->db->posts}.{$orderby}";1538 $orderby_clause = "{$wpdb->posts}.{$orderby}"; 1540 1539 break; 1541 1540 case 'rand': … … 1562 1561 } else { 1563 1562 // Default: order by post field. 1564 $orderby_clause = "{$ this->db->posts}.post_" . sanitize_key( $orderby );1563 $orderby_clause = "{$wpdb->posts}.post_" . sanitize_key( $orderby ); 1565 1564 } 1566 1565 … … 1652 1651 */ 1653 1652 public function get_posts() { 1653 global $wpdb; 1654 1654 1655 $this->parse_query(); 1655 1656 … … 1787 1788 switch ( $q['fields'] ) { 1788 1789 case 'ids': 1789 $fields = "{$ this->db->posts}.ID";1790 $fields = "{$wpdb->posts}.ID"; 1790 1791 break; 1791 1792 case 'id=>parent': 1792 $fields = "{$ this->db->posts}.ID, {$this->db->posts}.post_parent";1793 $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent"; 1793 1794 break; 1794 1795 default: 1795 $fields = "{$ this->db->posts}.*";1796 $fields = "{$wpdb->posts}.*"; 1796 1797 } 1797 1798 1798 1799 if ( '' !== $q['menu_order'] ) { 1799 $where .= " AND {$ this->db->posts}.menu_order = " . $q['menu_order'];1800 $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order']; 1800 1801 } 1801 1802 // The "m" parameter is meant for months but accepts datetimes of varying specificity 1802 1803 if ( $q['m'] ) { 1803 $where .= " AND YEAR({$ this->db->posts}.post_date)=" . substr($q['m'], 0, 4);1804 $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr($q['m'], 0, 4); 1804 1805 if ( strlen($q['m']) > 5 ) { 1805 $where .= " AND MONTH({$ this->db->posts}.post_date)=" . substr($q['m'], 4, 2);1806 $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 4, 2); 1806 1807 } 1807 1808 if ( strlen($q['m']) > 7 ) { 1808 $where .= " AND DAYOFMONTH({$ this->db->posts}.post_date)=" . substr($q['m'], 6, 2);1809 $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 6, 2); 1809 1810 } 1810 1811 if ( strlen($q['m']) > 9 ) { 1811 $where .= " AND HOUR({$ this->db->posts}.post_date)=" . substr($q['m'], 8, 2);1812 $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr($q['m'], 8, 2); 1812 1813 } 1813 1814 if ( strlen($q['m']) > 11 ) { 1814 $where .= " AND MINUTE({$ this->db->posts}.post_date)=" . substr($q['m'], 10, 2);1815 $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr($q['m'], 10, 2); 1815 1816 } 1816 1817 if ( strlen($q['m']) > 13 ) { 1817 $where .= " AND SECOND({$ this->db->posts}.post_date)=" . substr($q['m'], 12, 2);1818 $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr($q['m'], 12, 2); 1818 1819 } 1819 1820 } … … 1879 1880 1880 1881 if ( '' !== $q['title'] ) { 1881 $where .= $ this->db->prepare( " AND {$this->db->posts}.post_title = %s", stripslashes( $q['title'] ) );1882 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q['title'] ) ); 1882 1883 } 1883 1884 … … 1885 1886 if ( '' != $q['name'] ) { 1886 1887 $q['name'] = sanitize_title_for_query( $q['name'] ); 1887 $where .= " AND {$ this->db->posts}.post_name = '" . $q['name'] . "'";1888 $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'"; 1888 1889 } elseif ( '' != $q['pagename'] ) { 1889 1890 if ( isset($this->queried_object_id) ) { … … 1914 1915 $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); 1915 1916 $q['name'] = $q['pagename']; 1916 $where .= " AND ({$ this->db->posts}.ID = '$reqpage')";1917 $where .= " AND ({$wpdb->posts}.ID = '$reqpage')"; 1917 1918 $reqpage_obj = get_post( $reqpage ); 1918 1919 if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { … … 1926 1927 $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); 1927 1928 $q['name'] = $q['attachment']; 1928 $where .= " AND {$ this->db->posts}.post_name = '" . $q['attachment'] . "'";1929 $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'"; 1929 1930 } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { 1930 1931 $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); 1931 1932 $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'"; 1932 $where .= " AND {$ this->db->posts}.post_name IN ($post_name__in)";1933 $where .= " AND {$wpdb->posts}.post_name IN ($post_name__in)"; 1933 1934 } 1934 1935 … … 1939 1940 // If a post number is specified, load that post 1940 1941 if ( $q['p'] ) { 1941 $where .= " AND {$ this->db->posts}.ID = " . $q['p'];1942 $where .= " AND {$wpdb->posts}.ID = " . $q['p']; 1942 1943 } elseif ( $q['post__in'] ) { 1943 1944 $post__in = implode(',', array_map( 'absint', $q['post__in'] )); 1944 $where .= " AND {$ this->db->posts}.ID IN ($post__in)";1945 $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; 1945 1946 } elseif ( $q['post__not_in'] ) { 1946 1947 $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] )); 1947 $where .= " AND {$ this->db->posts}.ID NOT IN ($post__not_in)";1948 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; 1948 1949 } 1949 1950 1950 1951 if ( is_numeric( $q['post_parent'] ) ) { 1951 $where .= $ this->db->prepare( " AND {$this->db->posts}.post_parent = %d ", $q['post_parent'] );1952 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $q['post_parent'] ); 1952 1953 } elseif ( $q['post_parent__in'] ) { 1953 1954 $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); 1954 $where .= " AND {$ this->db->posts}.post_parent IN ($post_parent__in)";1955 $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; 1955 1956 } elseif ( $q['post_parent__not_in'] ) { 1956 1957 $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); 1957 $where .= " AND {$ this->db->posts}.post_parent NOT IN ($post_parent__not_in)";1958 $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; 1958 1959 } 1959 1960 … … 1961 1962 if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) { 1962 1963 $q['p'] = $q['page_id']; 1963 $where = " AND {$ this->db->posts}.ID = " . $q['page_id'];1964 $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; 1964 1965 } 1965 1966 } … … 1986 1987 $this->parse_tax_query( $q ); 1987 1988 1988 $clauses = $this->tax_query->get_sql( $ this->db->posts, 'ID' );1989 $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); 1989 1990 1990 1991 $join .= $clauses['join']; … … 2070 2071 2071 2072 if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { 2072 $groupby = "{$ this->db->posts}.ID";2073 $groupby = "{$wpdb->posts}.ID"; 2073 2074 } 2074 2075 … … 2087 2088 if ( ! empty( $q['author__not_in'] ) ) { 2088 2089 $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) ); 2089 $where .= " AND {$ this->db->posts}.post_author NOT IN ($author__not_in) ";2090 $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) "; 2090 2091 } elseif ( ! empty( $q['author__in'] ) ) { 2091 2092 $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) ); 2092 $where .= " AND {$ this->db->posts}.post_author IN ($author__in) ";2093 $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; 2093 2094 } 2094 2095 … … 2108 2109 if ( $q['author'] ) 2109 2110 $q['author'] = $q['author']->ID; 2110 $whichauthor .= " AND ({$ this->db->posts}.post_author = " . absint($q['author']) . ')';2111 $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint($q['author']) . ')'; 2111 2112 } 2112 2113 … … 2114 2115 2115 2116 if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { 2116 $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $ this->db->posts );2117 $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); 2117 2118 } 2118 2119 $where .= $search . $whichauthor . $whichmimetype; 2119 2120 2120 2121 if ( ! empty( $this->meta_query->queries ) ) { 2121 $clauses = $this->meta_query->get_sql( 'post', $ this->db->posts, 'ID', $this );2122 $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 2122 2123 $join .= $clauses['join']; 2123 2124 $where .= $clauses['where']; … … 2140 2141 $orderby = ''; 2141 2142 } else { 2142 $orderby = "{$ this->db->posts}.post_date " . $q['order'];2143 $orderby = "{$wpdb->posts}.post_date " . $q['order']; 2143 2144 } 2144 2145 } elseif ( 'none' == $q['orderby'] ) { 2145 2146 $orderby = ''; 2146 2147 } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { 2147 $orderby = "FIELD( {$ this->db->posts}.ID, $post__in )";2148 $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; 2148 2149 } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { 2149 $orderby = "FIELD( {$ this->db->posts}.post_parent, $post_parent__in )";2150 $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; 2150 2151 } elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) { 2151 $orderby = "FIELD( {$ this->db->posts}.post_name, $post_name__in )";2152 $orderby = "FIELD( {$wpdb->posts}.post_name, $post_name__in )"; 2152 2153 } else { 2153 2154 $orderby_array = array(); … … 2181 2182 2182 2183 if ( empty( $orderby ) ) { 2183 $orderby = "{$ this->db->posts}.post_date " . $q['order'];2184 $orderby = "{$wpdb->posts}.post_date " . $q['order']; 2184 2185 } elseif ( ! empty( $q['order'] ) ) { 2185 2186 $orderby .= " {$q['order']}"; … … 2221 2222 2222 2223 if ( isset( $q['post_password'] ) ) { 2223 $where .= $ this->db->prepare( " AND {$this->db->posts}.post_password = %s", $q['post_password'] );2224 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q['post_password'] ); 2224 2225 if ( empty( $q['perm'] ) ) { 2225 2226 $q['perm'] = 'readable'; 2226 2227 } 2227 2228 } elseif ( isset( $q['has_password'] ) ) { 2228 $where .= sprintf( " AND {$ this->db->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' );2229 $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' ); 2229 2230 } 2230 2231 2231 2232 if ( ! empty( $q['comment_status'] ) ) { 2232 $where .= $ this->db->prepare( " AND {$this->db->posts}.comment_status = %s ", $q['comment_status'] );2233 $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q['comment_status'] ); 2233 2234 } 2234 2235 2235 2236 if ( ! empty( $q['ping_status'] ) ) { 2236 $where .= $ this->db->prepare( " AND {$this->db->posts}.ping_status = %s ", $q['ping_status'] );2237 $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] ); 2237 2238 } 2238 2239 … … 2242 2243 $where .= ' AND 1=0 '; 2243 2244 } else { 2244 $where .= " AND {$ this->db->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')";2245 $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; 2245 2246 } 2246 2247 } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { 2247 $where .= " AND {$ this->db->posts}.post_type IN ('" . join("', '", $post_type) . "')";2248 $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", $post_type) . "')"; 2248 2249 } elseif ( ! empty( $post_type ) ) { 2249 $where .= " AND {$ this->db->posts}.post_type = '$post_type'";2250 $where .= " AND {$wpdb->posts}.post_type = '$post_type'"; 2250 2251 $post_type_object = get_post_type_object ( $post_type ); 2251 2252 } elseif ( $this->is_attachment ) { 2252 $where .= " AND {$ this->db->posts}.post_type = 'attachment'";2253 $where .= " AND {$wpdb->posts}.post_type = 'attachment'"; 2253 2254 $post_type_object = get_post_type_object ( 'attachment' ); 2254 2255 } elseif ( $this->is_page ) { 2255 $where .= " AND {$ this->db->posts}.post_type = 'page'";2256 $where .= " AND {$wpdb->posts}.post_type = 'page'"; 2256 2257 $post_type_object = get_post_type_object ( 'page' ); 2257 2258 } else { 2258 $where .= " AND {$ this->db->posts}.post_type = 'post'";2259 $where .= " AND {$wpdb->posts}.post_type = 'post'"; 2259 2260 $post_type_object = get_post_type_object ( 'post' ); 2260 2261 } … … 2285 2286 foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { 2286 2287 if ( ! in_array( $status, $q_status ) ) { 2287 $e_status[] = "{$ this->db->posts}.post_status <> '$status'";2288 $e_status[] = "{$wpdb->posts}.post_status <> '$status'"; 2288 2289 } 2289 2290 } … … 2292 2293 if ( in_array( $status, $q_status ) ) { 2293 2294 if ( 'private' == $status ) { 2294 $p_status[] = "{$ this->db->posts}.post_status = '$status'";2295 $p_status[] = "{$wpdb->posts}.post_status = '$status'"; 2295 2296 } else { 2296 $r_status[] = "{$ this->db->posts}.post_status = '$status'";2297 $r_status[] = "{$wpdb->posts}.post_status = '$status'"; 2297 2298 } 2298 2299 } … … 2310 2311 if ( !empty($r_status) ) { 2311 2312 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) { 2312 $statuswheres[] = "({$ this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";2313 $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; 2313 2314 } else { 2314 2315 $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; … … 2317 2318 if ( !empty($p_status) ) { 2318 2319 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) { 2319 $statuswheres[] = "({$ this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";2320 $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; 2320 2321 } else { 2321 2322 $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; … … 2323 2324 } 2324 2325 if ( $post_status_join ) { 2325 $join .= " LEFT JOIN {$ this->db->posts} AS p2 ON ({$this->db->posts}.post_parent = p2.ID) ";2326 $join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) "; 2326 2327 foreach ( $statuswheres as $index => $statuswhere ) { 2327 $statuswheres[$index] = "($statuswhere OR ({$ this->db->posts}.post_status = 'inherit' AND " . str_replace( $this->db->posts, 'p2', $statuswhere ) . "))";2328 $statuswheres[$index] = "($statuswhere OR ({$wpdb->posts}.post_status = 'inherit' AND " . str_replace( $wpdb->posts, 'p2', $statuswhere ) . "))"; 2328 2329 } 2329 2330 } … … 2333 2334 } 2334 2335 } elseif ( !$this->is_singular ) { 2335 $where .= " AND ({$ this->db->posts}.post_status = 'publish'";2336 $where .= " AND ({$wpdb->posts}.post_status = 'publish'"; 2336 2337 2337 2338 // Add public states. … … 2340 2341 if ( 'publish' == $state ) // Publish is hard-coded above. 2341 2342 continue; 2342 $where .= " OR {$ this->db->posts}.post_status = '$state'";2343 $where .= " OR {$wpdb->posts}.post_status = '$state'"; 2343 2344 } 2344 2345 … … 2347 2348 $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); 2348 2349 foreach ( (array) $admin_all_states as $state ) { 2349 $where .= " OR {$ this->db->posts}.post_status = '$state'";2350 $where .= " OR {$wpdb->posts}.post_status = '$state'"; 2350 2351 } 2351 2352 } … … 2355 2356 $private_states = get_post_stati( array('private' => true) ); 2356 2357 foreach ( (array) $private_states as $state ) { 2357 $where .= current_user_can( $read_private_cap ) ? " OR {$ this->db->posts}.post_status = '$state'" : " OR {$this->db->posts}.post_author = $user_id AND {$this->db->posts}.post_status = '$state'";2358 $where .= current_user_can( $read_private_cap ) ? " OR {$wpdb->posts}.post_status = '$state'" : " OR {$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$state'"; 2358 2359 } 2359 2360 } … … 2407 2408 if ( $this->is_comment_feed && ! $this->is_singular ) { 2408 2409 if ( $this->is_archive || $this->is_search ) { 2409 $cjoin = "JOIN {$ this->db->posts} ON ({$this->db->comments}.comment_post_ID = {$this->db->posts}.ID) $join ";2410 $cjoin = "JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) $join "; 2410 2411 $cwhere = "WHERE comment_approved = '1' $where"; 2411 $cgroupby = "{$ this->db->comments}.comment_id";2412 $cgroupby = "{$wpdb->comments}.comment_id"; 2412 2413 } else { // Other non singular e.g. front 2413 $cjoin = "JOIN {$ this->db->posts} ON ( {$this->db->comments}.comment_post_ID = {$this->db->posts}.ID )";2414 $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )"; 2414 2415 $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'"; 2415 2416 $cgroupby = ''; … … 2470 2471 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 2471 2472 2472 $comments = (array) $ this->db->get_results("SELECT $distinct {$this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits");2473 $comments = (array) $wpdb->get_results("SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"); 2473 2474 // Convert to WP_Comment 2474 2475 $this->comments = array_map( 'get_comment', $comments ); … … 2483 2484 $join = ''; 2484 2485 if ( $post_ids ) { 2485 $where = "AND {$ this->db->posts}.ID IN ($post_ids) ";2486 $where = "AND {$wpdb->posts}.ID IN ($post_ids) "; 2486 2487 } else { 2487 2488 $where = "AND 0"; … … 2725 2726 $found_rows = 'SQL_CALC_FOUND_ROWS'; 2726 2727 2727 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$ this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits";2728 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; 2728 2729 2729 2730 if ( !$q['suppress_filters'] ) { … … 2759 2760 if ( 'ids' == $q['fields'] ) { 2760 2761 if ( null === $this->posts ) { 2761 $this->posts = $ this->db->get_col( $this->request );2762 $this->posts = $wpdb->get_col( $this->request ); 2762 2763 } 2763 2764 … … 2771 2772 if ( 'id=>parent' == $q['fields'] ) { 2772 2773 if ( null === $this->posts ) { 2773 $this->posts = $ this->db->get_results( $this->request );2774 $this->posts = $wpdb->get_results( $this->request ); 2774 2775 } 2775 2776 … … 2789 2790 2790 2791 if ( null === $this->posts ) { 2791 $split_the_query = ( $old_request == $this->request && "{$ this->db->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );2792 $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 2792 2793 2793 2794 /** … … 2808 2809 // First get the IDs and then fill in the objects 2809 2810 2810 $this->request = "SELECT $found_rows $distinct {$ this->db->posts}.ID FROM {$this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits";2811 $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; 2811 2812 2812 2813 /** … … 2820 2821 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 2821 2822 2822 $ids = $ this->db->get_col( $this->request );2823 $ids = $wpdb->get_col( $this->request ); 2823 2824 2824 2825 if ( $ids ) { … … 2830 2831 } 2831 2832 } else { 2832 $this->posts = $ this->db->get_results( $this->request );2833 $this->posts = $wpdb->get_results( $this->request ); 2833 2834 $this->set_found_posts( $q, $limits ); 2834 2835 } … … 2870 2871 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 2871 2872 2872 $comments_request = "SELECT {$ this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits";2873 $comments = $ this->db->get_results($comments_request);2873 $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; 2874 $comments = $wpdb->get_results($comments_request); 2874 2875 // Convert to WP_Comment 2875 2876 $this->comments = array_map( 'get_comment', $comments ); … … 3018 3019 */ 3019 3020 private function set_found_posts( $q, $limits ) { 3021 global $wpdb; 3020 3022 // Bail if posts is an empty array. Continue if posts is an empty string, 3021 3023 // null, or false to accommodate caching plugins that fill posts later. … … 3032 3034 * @param WP_Query &$this The WP_Query instance (passed by reference). 3033 3035 */ 3034 $this->found_posts = $ this->db->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );3036 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 3035 3037 } else { 3036 3038 $this->found_posts = count( $this->posts ); … … 3329 3331 */ 3330 3332 public function __construct( $query = '' ) { 3331 $this->db = $GLOBALS['wpdb'];3332 3333 3333 if ( ! empty( $query ) ) { 3334 3334 $this->query( $query );
Note: See TracChangeset
for help on using the changeset viewer.