Changeset 47122 for trunk/src/wp-includes/class-wp-query.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-query.php (modified) (43 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r47052 r47122 772 772 $qv['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : ''; 773 773 $qv['paged'] = absint( $qv['paged'] ); 774 $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers775 $qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers774 $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // Comma-separated list of positive or negative integers. 775 $qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // Comma-separated list of positive or negative integers. 776 776 $qv['pagename'] = trim( $qv['pagename'] ); 777 777 $qv['name'] = trim( $qv['name'] ); … … 813 813 $this->is_single = true; 814 814 } elseif ( ( '' !== $qv['hour'] ) && ( '' !== $qv['minute'] ) && ( '' !== $qv['second'] ) && ( '' != $qv['year'] ) && ( '' != $qv['monthnum'] ) && ( '' != $qv['day'] ) ) { 815 // If year, month, day, hour, minute, and second are set, a single816 // post is being queried.815 // If year, month, day, hour, minute, and second are set, 816 // a single post is being queried. 817 817 $this->is_single = true; 818 818 } elseif ( '' != $qv['pagename'] || ! empty( $qv['page_id'] ) ) { … … 949 949 } 950 950 951 // if we're previewing inside the write screen951 // If we're previewing inside the write screen. 952 952 if ( '' != $qv['preview'] ) { 953 953 $this->is_preview = true; … … 975 975 } 976 976 977 // Correct is_* for page_on_front and page_for_posts977 // Correct `is_*` for 'page_on_front' and 'page_for_posts'. 978 978 if ( $this->is_home && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { 979 979 $_query = wp_parse_args( $this->query ); 980 // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.980 // 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'. 981 981 if ( isset( $_query['pagename'] ) && '' == $_query['pagename'] ) { 982 982 unset( $_query['pagename'] ); … … 989 989 $this->is_home = false; 990 990 $qv['page_id'] = get_option( 'page_on_front' ); 991 // Correct <!--nextpage--> for page_on_front991 // Correct <!--nextpage--> for 'page_on_front'. 992 992 if ( ! empty( $qv['paged'] ) ) { 993 993 $qv['page'] = $qv['paged']; … … 1002 1002 if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) { 1003 1003 if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) { 1004 // See if we also have a post with the same slug 1004 // See if we also have a post with the same slug. 1005 1005 $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' ); 1006 1006 if ( $post ) { … … 1062 1062 1063 1063 $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; 1064 // Done correcting is_* for page_on_front and page_for_posts1064 // Done correcting `is_*` for 'page_on_front' and 'page_for_posts'. 1065 1065 1066 1066 if ( '404' == $qv['error'] ) { … … 1109 1109 foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) { 1110 1110 if ( 'post_tag' == $taxonomy ) { 1111 continue; // Handled further down in the $q['tag'] block1111 continue; // Handled further down in the $q['tag'] block. 1112 1112 } 1113 1113 … … 1149 1149 } 1150 1150 1151 // If query string 'cat' is an array, implode it.1151 // If query string 'cat' is an array, implode it. 1152 1152 if ( is_array( $q['cat'] ) ) { 1153 1153 $q['cat'] = implode( ',', $q['cat'] ); 1154 1154 } 1155 1155 1156 // Category stuff 1156 // Category stuff. 1157 1157 1158 if ( ! empty( $q['cat'] ) && ! $this->is_singular ) { 1158 1159 $cat_in = array(); … … 1232 1233 } 1233 1234 1234 // If query string 'tag' is array, implode it.1235 // If query string 'tag' is array, implode it. 1235 1236 if ( is_array( $q['tag'] ) ) { 1236 1237 $q['tag'] = implode( ',', $q['tag'] ); 1237 1238 } 1238 1239 1239 // Tag stuff 1240 // Tag stuff. 1241 1240 1242 if ( '' != $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) { 1241 1243 if ( strpos( $q['tag'], ',' ) !== false ) { … … 1337 1339 $search = ''; 1338 1340 1339 // added slashes screw with quote grouping when done early, so done later1341 // Added slashes screw with quote grouping when done early, so done later. 1340 1342 $q['s'] = stripslashes( $q['s'] ); 1341 1343 if ( empty( $_GET['s'] ) && $this->is_main_query() ) { 1342 1344 $q['s'] = urldecode( $q['s'] ); 1343 1345 } 1344 // there are no line breaks in <input /> fields1346 // There are no line breaks in <input /> fields. 1345 1347 $q['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] ); 1346 1348 $q['search_terms_count'] = 1; … … 1351 1353 $q['search_terms_count'] = count( $matches[0] ); 1352 1354 $q['search_terms'] = $this->parse_search_terms( $matches[0] ); 1353 // if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence1355 // If the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence. 1354 1356 if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) { 1355 1357 $q['search_terms'] = array( $q['s'] ); … … 1425 1427 1426 1428 foreach ( $terms as $term ) { 1427 // keep before/after spaces when term is for exact match1429 // Keep before/after spaces when term is for exact match. 1428 1430 if ( preg_match( '/^".+"$/', $term ) ) { 1429 1431 $term = trim( $term, "\"'" ); … … 1515 1517 $search_orderby = ''; 1516 1518 1517 // sentence match in 'post_title'1519 // Sentence match in 'post_title'. 1518 1520 if ( $like ) { 1519 1521 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like ); 1520 1522 } 1521 1523 1522 // sanity limit, sort as sentence when more than 6 terms1523 // (few searches are longer than 6 terms and most titles are not) 1524 // Sanity limit, sort as sentence when more than 6 terms 1525 // (few searches are longer than 6 terms and most titles are not). 1524 1526 if ( $num_terms < 7 ) { 1525 // all words in title1527 // All words in title. 1526 1528 $search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 '; 1527 // any word in title, not needed when $num_terms == 11529 // Any word in title, not needed when $num_terms == 1. 1528 1530 if ( $num_terms > 1 ) { 1529 1531 $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; … … 1541 1543 } 1542 1544 } else { 1543 // single word or sentence search1545 // Single word or sentence search. 1544 1546 $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC'; 1545 1547 } … … 1773 1775 $q = &$this->query_vars; 1774 1776 1775 // Fill again in case pre_get_postsunset some vars.1777 // Fill again in case 'pre_get_posts' unset some vars. 1776 1778 $q = $this->fill_query_vars( $q ); 1777 1779 1778 // Parse meta query 1780 // Parse meta query. 1779 1781 $this->meta_query = new WP_Meta_Query(); 1780 1782 $this->meta_query->parse_query_vars( $q ); 1781 1783 1782 // Set a flag if a pre_get_postshook changed the query vars.1784 // Set a flag if a 'pre_get_posts' hook changed the query vars. 1783 1785 $hash = md5( serialize( $this->query_vars ) ); 1784 1786 if ( $hash != $this->query_vars_hash ) { … … 1788 1790 unset( $hash ); 1789 1791 1790 // First let's clear some variables 1792 // First let's clear some variables. 1791 1793 $distinct = ''; 1792 1794 $whichauthor = ''; … … 1872 1874 1873 1875 if ( $this->is_feed ) { 1874 // This overrides posts_per_page.1876 // This overrides 'posts_per_page'. 1875 1877 if ( ! empty( $q['posts_per_rss'] ) ) { 1876 1878 $q['posts_per_page'] = $q['posts_per_rss']; … … 1923 1925 $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order']; 1924 1926 } 1925 // The "m" parameter is meant for months but accepts datetimes of varying specificity 1927 // The "m" parameter is meant for months but accepts datetimes of varying specificity. 1926 1928 if ( $q['m'] ) { 1927 1929 $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr( $q['m'], 0, 4 ); … … 1943 1945 } 1944 1946 1945 // Handle the other individual date parameters 1947 // Handle the other individual date parameters. 1946 1948 $date_parameters = array(); 1947 1949 … … 1980 1982 unset( $date_parameters, $date_query ); 1981 1983 1982 // Handle complex date queries 1984 // Handle complex date queries. 1983 1985 if ( ! empty( $q['date_query'] ) ) { 1984 1986 $this->date_query = new WP_Date_Query( $q['date_query'] ); … … 2005 2007 // Only one request for a slug is possible, this is why name & pagename are overwritten above. 2006 2008 break; 2007 } // end foreach2009 } // End foreach. 2008 2010 unset( $ptype_obj ); 2009 2011 } … … 2073 2075 } 2074 2076 2075 // If a post number is specified, load that post 2077 // If a post number is specified, load that post. 2076 2078 if ( $q['p'] ) { 2077 2079 $where .= " AND {$wpdb->posts}.ID = " . $q['p']; … … 2118 2120 } 2119 2121 2120 // Taxonomies 2122 // Taxonomies. 2121 2123 if ( ! $this->is_singular ) { 2122 2124 $this->parse_tax_query( $q ); … … 2130 2132 if ( $this->is_tax ) { 2131 2133 if ( empty( $post_type ) ) { 2132 // Do a fully inclusive search for currently registered post types of queried taxonomies 2134 // Do a fully inclusive search for currently registered post types of queried taxonomies. 2133 2135 $post_type = array(); 2134 2136 $taxonomies = array_keys( $this->tax_query->queried_terms ); … … 2182 2184 } 2183 2185 2184 // 'cat', 'category_name', 'tag_id' 2186 // 'cat', 'category_name', 'tag_id'. 2185 2187 foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { 2186 2188 if ( empty( $queried_items['terms'][0] ) ) { … … 2211 2213 } 2212 2214 2213 // Author/user stuff 2215 // Author/user stuff. 2214 2216 2215 2217 if ( ! empty( $q['author'] ) && $q['author'] != '0' ) { … … 2231 2233 } 2232 2234 2233 // Author stuff for nice URLs 2235 // Author stuff for nice URLs. 2234 2236 2235 2237 if ( '' != $q['author_name'] ) { … … 2237 2239 $q['author_name'] = explode( '/', $q['author_name'] ); 2238 2240 if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) { 2239 $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // no trailing slash2241 $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash. 2240 2242 } else { 2241 $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // there was a trailing slash2243 $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // There was a trailing slash. 2242 2244 } 2243 2245 } … … 2277 2279 } 2278 2280 2279 // MIME-Type stuff for attachment browsing 2281 // MIME-Type stuff for attachment browsing. 2280 2282 2281 2283 if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { … … 2565 2567 } 2566 2568 2567 // Paging 2569 // Paging. 2568 2570 if ( empty( $q['nopaging'] ) && ! $this->is_singular ) { 2569 2571 $page = absint( $q['paged'] ); … … 2582 2584 } 2583 2585 2584 // Comments feeds 2586 // Comments feeds. 2585 2587 if ( $this->is_comment_feed && ! $this->is_singular ) { 2586 2588 if ( $this->is_archive || $this->is_search ) { … … 2588 2590 $cwhere = "WHERE comment_approved = '1' $where"; 2589 2591 $cgroupby = "{$wpdb->comments}.comment_id"; 2590 } else { // Other non singular e.g. front2592 } else { // Other non-singular, e.g. front. 2591 2593 $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )"; 2592 2594 $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'"; … … 2651 2653 2652 2654 $comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" ); 2653 // Convert to WP_Comment 2655 // Convert to WP_Comment. 2654 2656 $this->comments = array_map( 'get_comment', $comments ); 2655 2657 $this->comment_count = count( $this->comments ); … … 2991 2993 2992 2994 if ( $split_the_query ) { 2993 // First get the IDs and then fill in the objects 2995 // First get the IDs and then fill in the objects. 2994 2996 2995 2997 $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; … … 3057 3059 $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; 3058 3060 $comments = $wpdb->get_results( $comments_request ); 3059 // Convert to WP_Comment 3061 // Convert to WP_Comment. 3060 3062 $this->comments = array_map( 'get_comment', $comments ); 3061 3063 $this->comment_count = count( $this->comments ); … … 3112 3114 } 3113 3115 3114 // Put sticky posts at the top of the posts array 3116 // Put sticky posts at the top of the posts array. 3115 3117 $sticky_posts = get_option( 'sticky_posts' ); 3116 3118 if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) { … … 3121 3123 if ( in_array( $this->posts[ $i ]->ID, $sticky_posts ) ) { 3122 3124 $sticky_post = $this->posts[ $i ]; 3123 // Remove sticky from current position 3125 // Remove sticky from current position. 3124 3126 array_splice( $this->posts, $i, 1 ); 3125 // Move to front, after other stickies 3127 // Move to front, after other stickies. 3126 3128 array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); 3127 3129 // Increment the sticky offset. The next sticky will be placed at this offset. 3128 3130 $sticky_offset++; 3129 // Remove post from sticky posts array 3131 // Remove post from sticky posts array. 3130 3132 $offset = array_search( $sticky_post->ID, $sticky_posts ); 3131 3133 unset( $sticky_posts[ $offset ] ); … … 3138 3140 } 3139 3141 3140 // Fetch sticky posts that weren't in the query results 3142 // Fetch sticky posts that weren't in the query results. 3141 3143 if ( ! empty( $sticky_posts ) ) { 3142 3144 $stickies = get_posts( … … 3281 3283 $this->in_the_loop = true; 3282 3284 3283 if ( $this->current_post == -1 ) { // loop has just started3285 if ( $this->current_post == -1 ) { // Loop has just started. 3284 3286 /** 3285 3287 * Fires once the loop is started. … … 3317 3319 */ 3318 3320 do_action_ref_array( 'loop_end', array( &$this ) ); 3319 // Do some cleaning up after the loop 3321 // Do some cleaning up after the loop. 3320 3322 $this->rewind_posts(); 3321 3323 } elseif ( 0 === $this->post_count ) { … … 3790 3792 } 3791 3793 3792 // Only a Taxonomy provided.3794 // Only a taxonomy provided. 3793 3795 if ( empty( $term ) ) { 3794 3796 return true; … … 3887 3889 */ 3888 3890 public function is_front_page() { 3889 // most likely case3891 // Most likely case. 3890 3892 if ( 'posts' == get_option( 'show_on_front' ) && $this->is_home() ) { 3891 3893 return true;
Note: See TracChangeset
for help on using the changeset viewer.