Changeset 60927
- Timestamp:
- 10/13/2025 09:37:03 PM (3 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-query.php (modified) (91 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r60697 r60927 811 811 812 812 $this->query_vars = $this->fill_query_vars( $this->query_vars ); 813 $q v= &$this->query_vars;813 $query_vars = &$this->query_vars; 814 814 $this->query_vars_changed = true; 815 815 816 if ( ! empty( $q v['robots'] ) ) {816 if ( ! empty( $query_vars['robots'] ) ) { 817 817 $this->is_robots = true; 818 } elseif ( ! empty( $q v['favicon'] ) ) {818 } elseif ( ! empty( $query_vars['favicon'] ) ) { 819 819 $this->is_favicon = true; 820 820 } 821 821 822 if ( ! is_scalar( $q v['p'] ) || (int) $qv['p'] < 0 ) {823 $q v['p'] = 0;824 $q v['error'] = '404';822 if ( ! is_scalar( $query_vars['p'] ) || (int) $query_vars['p'] < 0 ) { 823 $query_vars['p'] = 0; 824 $query_vars['error'] = '404'; 825 825 } else { 826 $q v['p'] = (int) $qv['p'];827 } 828 829 $q v['page_id'] = is_scalar( $qv['page_id'] ) ? absint( $qv['page_id'] ) : 0;830 $q v['year'] = is_scalar( $qv['year'] ) ? absint( $qv['year'] ) : 0;831 $q v['monthnum'] = is_scalar( $qv['monthnum'] ) ? absint( $qv['monthnum'] ) : 0;832 $q v['day'] = is_scalar( $qv['day'] ) ? absint( $qv['day'] ) : 0;833 $q v['w'] = is_scalar( $qv['w'] ) ? absint( $qv['w'] ) : 0;834 $q v['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : '';835 $q v['paged'] = is_scalar( $qv['paged'] ) ? absint( $qv['paged'] ) : 0;836 $q v['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // Array or comma-separated list of positive or negative integers.837 $q v['author'] = is_scalar( $qv['author'] ) ? preg_replace( '|[^0-9,-]|', '', $qv['author'] ) : ''; // Comma-separated list of positive or negative integers.838 $q v['pagename'] = is_scalar( $qv['pagename'] ) ? trim( $qv['pagename'] ) : '';839 $q v['name'] = is_scalar( $qv['name'] ) ? trim( $qv['name'] ) : '';840 $q v['title'] = is_scalar( $qv['title'] ) ? trim( $qv['title'] ) : '';841 842 if ( is_scalar( $q v['hour'] ) && '' !== $qv['hour'] ) {843 $q v['hour'] = absint( $qv['hour'] );826 $query_vars['p'] = (int) $query_vars['p']; 827 } 828 829 $query_vars['page_id'] = is_scalar( $query_vars['page_id'] ) ? absint( $query_vars['page_id'] ) : 0; 830 $query_vars['year'] = is_scalar( $query_vars['year'] ) ? absint( $query_vars['year'] ) : 0; 831 $query_vars['monthnum'] = is_scalar( $query_vars['monthnum'] ) ? absint( $query_vars['monthnum'] ) : 0; 832 $query_vars['day'] = is_scalar( $query_vars['day'] ) ? absint( $query_vars['day'] ) : 0; 833 $query_vars['w'] = is_scalar( $query_vars['w'] ) ? absint( $query_vars['w'] ) : 0; 834 $query_vars['m'] = is_scalar( $query_vars['m'] ) ? preg_replace( '|[^0-9]|', '', $query_vars['m'] ) : ''; 835 $query_vars['paged'] = is_scalar( $query_vars['paged'] ) ? absint( $query_vars['paged'] ) : 0; 836 $query_vars['cat'] = preg_replace( '|[^0-9,-]|', '', $query_vars['cat'] ); // Array or comma-separated list of positive or negative integers. 837 $query_vars['author'] = is_scalar( $query_vars['author'] ) ? preg_replace( '|[^0-9,-]|', '', $query_vars['author'] ) : ''; // Comma-separated list of positive or negative integers. 838 $query_vars['pagename'] = is_scalar( $query_vars['pagename'] ) ? trim( $query_vars['pagename'] ) : ''; 839 $query_vars['name'] = is_scalar( $query_vars['name'] ) ? trim( $query_vars['name'] ) : ''; 840 $query_vars['title'] = is_scalar( $query_vars['title'] ) ? trim( $query_vars['title'] ) : ''; 841 842 if ( is_scalar( $query_vars['hour'] ) && '' !== $query_vars['hour'] ) { 843 $query_vars['hour'] = absint( $query_vars['hour'] ); 844 844 } else { 845 $q v['hour'] = '';846 } 847 848 if ( is_scalar( $q v['minute'] ) && '' !== $qv['minute'] ) {849 $q v['minute'] = absint( $qv['minute'] );845 $query_vars['hour'] = ''; 846 } 847 848 if ( is_scalar( $query_vars['minute'] ) && '' !== $query_vars['minute'] ) { 849 $query_vars['minute'] = absint( $query_vars['minute'] ); 850 850 } else { 851 $q v['minute'] = '';852 } 853 854 if ( is_scalar( $q v['second'] ) && '' !== $qv['second'] ) {855 $q v['second'] = absint( $qv['second'] );851 $query_vars['minute'] = ''; 852 } 853 854 if ( is_scalar( $query_vars['second'] ) && '' !== $query_vars['second'] ) { 855 $query_vars['second'] = absint( $query_vars['second'] ); 856 856 } else { 857 $q v['second'] = '';858 } 859 860 if ( is_scalar( $q v['menu_order'] ) && '' !== $qv['menu_order'] ) {861 $q v['menu_order'] = absint( $qv['menu_order'] );857 $query_vars['second'] = ''; 858 } 859 860 if ( is_scalar( $query_vars['menu_order'] ) && '' !== $query_vars['menu_order'] ) { 861 $query_vars['menu_order'] = absint( $query_vars['menu_order'] ); 862 862 } else { 863 $q v['menu_order'] = '';863 $query_vars['menu_order'] = ''; 864 864 } 865 865 866 866 // Fairly large, potentially too large, upper bound for search string lengths. 867 if ( ! is_scalar( $q v['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) {868 $q v['s'] = '';867 if ( ! is_scalar( $query_vars['s'] ) || ( ! empty( $query_vars['s'] ) && strlen( $query_vars['s'] ) > 1600 ) ) { 868 $query_vars['s'] = ''; 869 869 } 870 870 871 871 // Compat. Map subpost to attachment. 872 if ( is_scalar( $q v['subpost'] ) && '' != $qv['subpost'] ) {873 $q v['attachment'] = $qv['subpost'];874 } 875 if ( is_scalar( $q v['subpost_id'] ) && '' != $qv['subpost_id'] ) {876 $q v['attachment_id'] = $qv['subpost_id'];877 } 878 879 $q v['attachment_id'] = is_scalar( $qv['attachment_id'] ) ? absint( $qv['attachment_id'] ) : 0;880 881 if ( ( '' !== $q v['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {872 if ( is_scalar( $query_vars['subpost'] ) && '' != $query_vars['subpost'] ) { 873 $query_vars['attachment'] = $query_vars['subpost']; 874 } 875 if ( is_scalar( $query_vars['subpost_id'] ) && '' != $query_vars['subpost_id'] ) { 876 $query_vars['attachment_id'] = $query_vars['subpost_id']; 877 } 878 879 $query_vars['attachment_id'] = is_scalar( $query_vars['attachment_id'] ) ? absint( $query_vars['attachment_id'] ) : 0; 880 881 if ( ( '' !== $query_vars['attachment'] ) || ! empty( $query_vars['attachment_id'] ) ) { 882 882 $this->is_single = true; 883 883 $this->is_attachment = true; 884 } elseif ( '' !== $q v['name'] ) {884 } elseif ( '' !== $query_vars['name'] ) { 885 885 $this->is_single = true; 886 } elseif ( $q v['p'] ) {886 } elseif ( $query_vars['p'] ) { 887 887 $this->is_single = true; 888 } elseif ( '' !== $q v['pagename'] || ! empty( $qv['page_id'] ) ) {888 } elseif ( '' !== $query_vars['pagename'] || ! empty( $query_vars['page_id'] ) ) { 889 889 $this->is_page = true; 890 890 $this->is_single = false; … … 896 896 } 897 897 898 if ( '' !== $q v['second'] ) {898 if ( '' !== $query_vars['second'] ) { 899 899 $this->is_time = true; 900 900 $this->is_date = true; 901 901 } 902 902 903 if ( '' !== $q v['minute'] ) {903 if ( '' !== $query_vars['minute'] ) { 904 904 $this->is_time = true; 905 905 $this->is_date = true; 906 906 } 907 907 908 if ( '' !== $q v['hour'] ) {908 if ( '' !== $query_vars['hour'] ) { 909 909 $this->is_time = true; 910 910 $this->is_date = true; 911 911 } 912 912 913 if ( $q v['day'] ) {913 if ( $query_vars['day'] ) { 914 914 if ( ! $this->is_date ) { 915 $date = sprintf( '%04d-%02d-%02d', $q v['year'], $qv['monthnum'], $qv['day'] );916 if ( $q v['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) {917 $q v['error'] = '404';915 $date = sprintf( '%04d-%02d-%02d', $query_vars['year'], $query_vars['monthnum'], $query_vars['day'] ); 916 if ( $query_vars['monthnum'] && $query_vars['year'] && ! wp_checkdate( $query_vars['monthnum'], $query_vars['day'], $query_vars['year'], $date ) ) { 917 $query_vars['error'] = '404'; 918 918 } else { 919 919 $this->is_day = true; … … 923 923 } 924 924 925 if ( $q v['monthnum'] ) {925 if ( $query_vars['monthnum'] ) { 926 926 if ( ! $this->is_date ) { 927 if ( 12 < $q v['monthnum'] ) {928 $q v['error'] = '404';927 if ( 12 < $query_vars['monthnum'] ) { 928 $query_vars['error'] = '404'; 929 929 } else { 930 930 $this->is_month = true; … … 934 934 } 935 935 936 if ( $q v['year'] ) {936 if ( $query_vars['year'] ) { 937 937 if ( ! $this->is_date ) { 938 938 $this->is_year = true; … … 941 941 } 942 942 943 if ( $q v['m'] ) {943 if ( $query_vars['m'] ) { 944 944 $this->is_date = true; 945 if ( strlen( $q v['m'] ) > 9 ) {945 if ( strlen( $query_vars['m'] ) > 9 ) { 946 946 $this->is_time = true; 947 } elseif ( strlen( $q v['m'] ) > 7 ) {947 } elseif ( strlen( $query_vars['m'] ) > 7 ) { 948 948 $this->is_day = true; 949 } elseif ( strlen( $q v['m'] ) > 5 ) {949 } elseif ( strlen( $query_vars['m'] ) > 5 ) { 950 950 $this->is_month = true; 951 951 } else { … … 954 954 } 955 955 956 if ( $q v['w'] ) {956 if ( $query_vars['w'] ) { 957 957 $this->is_date = true; 958 958 } 959 959 960 960 $this->query_vars_hash = false; 961 $this->parse_tax_query( $q v);961 $this->parse_tax_query( $query_vars ); 962 962 963 963 foreach ( $this->tax_query->queries as $tax_query ) { … … 981 981 unset( $tax_query ); 982 982 983 if ( empty( $q v['author'] ) || ( '0' == $qv['author'] ) ) {983 if ( empty( $query_vars['author'] ) || ( '0' == $query_vars['author'] ) ) { 984 984 $this->is_author = false; 985 985 } else { … … 987 987 } 988 988 989 if ( '' !== $q v['author_name'] ) {989 if ( '' !== $query_vars['author_name'] ) { 990 990 $this->is_author = true; 991 991 } 992 992 993 if ( ! empty( $q v['post_type'] ) && ! is_array( $qv['post_type'] ) ) {994 $post_type_obj = get_post_type_object( $q v['post_type'] );993 if ( ! empty( $query_vars['post_type'] ) && ! is_array( $query_vars['post_type'] ) ) { 994 $post_type_obj = get_post_type_object( $query_vars['post_type'] ); 995 995 if ( ! empty( $post_type_obj->has_archive ) ) { 996 996 $this->is_post_type_archive = true; … … 1003 1003 } 1004 1004 1005 if ( '' != $q v['feed'] ) {1005 if ( '' != $query_vars['feed'] ) { 1006 1006 $this->is_feed = true; 1007 1007 } 1008 1008 1009 if ( '' != $q v['embed'] ) {1009 if ( '' != $query_vars['embed'] ) { 1010 1010 $this->is_embed = true; 1011 1011 } 1012 1012 1013 if ( '' != $q v['tb'] ) {1013 if ( '' != $query_vars['tb'] ) { 1014 1014 $this->is_trackback = true; 1015 1015 } 1016 1016 1017 if ( '' != $q v['paged'] && ( (int) $qv['paged'] > 1 ) ) {1017 if ( '' != $query_vars['paged'] && ( (int) $query_vars['paged'] > 1 ) ) { 1018 1018 $this->is_paged = true; 1019 1019 } 1020 1020 1021 1021 // If we're previewing inside the write screen. 1022 if ( '' != $q v['preview'] ) {1022 if ( '' != $query_vars['preview'] ) { 1023 1023 $this->is_preview = true; 1024 1024 } … … 1028 1028 } 1029 1029 1030 if ( str_contains( $q v['feed'], 'comments-' ) ) {1031 $q v['feed'] = str_replace( 'comments-', '', $qv['feed'] );1032 $q v['withcomments'] = 1;1030 if ( str_contains( $query_vars['feed'], 'comments-' ) ) { 1031 $query_vars['feed'] = str_replace( 'comments-', '', $query_vars['feed'] ); 1032 $query_vars['withcomments'] = 1; 1033 1033 } 1034 1034 1035 1035 $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; 1036 1036 1037 if ( $this->is_feed && ( ! empty( $q v['withcomments'] ) || ( empty( $qv['withoutcomments'] ) && $this->is_singular ) ) ) {1037 if ( $this->is_feed && ( ! empty( $query_vars['withcomments'] ) || ( empty( $query_vars['withoutcomments'] ) && $this->is_singular ) ) ) { 1038 1038 $this->is_comment_feed = true; 1039 1039 } … … 1056 1056 1057 1057 if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage' ) ) ) { 1058 $this->is_page = true;1059 $this->is_home = false;1060 $q v['page_id'] = get_option( 'page_on_front' );1058 $this->is_page = true; 1059 $this->is_home = false; 1060 $query_vars['page_id'] = get_option( 'page_on_front' ); 1061 1061 // Correct <!--nextpage--> for 'page_on_front'. 1062 if ( ! empty( $q v['paged'] ) ) {1063 $q v['page'] = $qv['paged'];1064 unset( $q v['paged'] );1065 } 1066 } 1067 } 1068 1069 if ( '' !== $q v['pagename'] ) {1070 $this->queried_object = get_page_by_path( $q v['pagename'] );1062 if ( ! empty( $query_vars['paged'] ) ) { 1063 $query_vars['page'] = $query_vars['paged']; 1064 unset( $query_vars['paged'] ); 1065 } 1066 } 1067 } 1068 1069 if ( '' !== $query_vars['pagename'] ) { 1070 $this->queried_object = get_page_by_path( $query_vars['pagename'] ); 1071 1071 1072 1072 if ( $this->queried_object && 'attachment' === $this->queried_object->post_type ) { 1073 1073 if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) { 1074 1074 // See if we also have a post with the same slug. 1075 $post = get_page_by_path( $q v['pagename'], OBJECT, 'post' );1075 $post = get_page_by_path( $query_vars['pagename'], OBJECT, 'post' ); 1076 1076 if ( $post ) { 1077 1077 $this->queried_object = $post; … … 1099 1099 } 1100 1100 1101 if ( $q v['page_id'] ) {1102 if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == $q v['page_id'] ) {1101 if ( $query_vars['page_id'] ) { 1102 if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == $query_vars['page_id'] ) { 1103 1103 $this->is_page = false; 1104 1104 $this->is_home = true; … … 1106 1106 } 1107 1107 1108 if ( get_option( 'wp_page_for_privacy_policy' ) == $q v['page_id'] ) {1108 if ( get_option( 'wp_page_for_privacy_policy' ) == $query_vars['page_id'] ) { 1109 1109 $this->is_privacy_policy = true; 1110 1110 } 1111 1111 } 1112 1112 1113 if ( ! empty( $q v['post_type'] ) ) {1114 if ( is_array( $q v['post_type'] ) ) {1115 $q v['post_type'] = array_map( 'sanitize_key', array_unique( $qv['post_type'] ) );1116 sort( $q v['post_type'] );1113 if ( ! empty( $query_vars['post_type'] ) ) { 1114 if ( is_array( $query_vars['post_type'] ) ) { 1115 $query_vars['post_type'] = array_map( 'sanitize_key', array_unique( $query_vars['post_type'] ) ); 1116 sort( $query_vars['post_type'] ); 1117 1117 } else { 1118 $q v['post_type'] = sanitize_key( $qv['post_type'] );1119 } 1120 } 1121 1122 if ( ! empty( $q v['post_status'] ) ) {1123 if ( is_array( $q v['post_status'] ) ) {1124 $q v['post_status'] = array_map( 'sanitize_key', array_unique( $qv['post_status'] ) );1125 sort( $q v['post_status'] );1118 $query_vars['post_type'] = sanitize_key( $query_vars['post_type'] ); 1119 } 1120 } 1121 1122 if ( ! empty( $query_vars['post_status'] ) ) { 1123 if ( is_array( $query_vars['post_status'] ) ) { 1124 $query_vars['post_status'] = array_map( 'sanitize_key', array_unique( $query_vars['post_status'] ) ); 1125 sort( $query_vars['post_status'] ); 1126 1126 } else { 1127 $q v['post_status'] = preg_replace( '|[^a-z0-9_,-]|', '', $qv['post_status'] );1128 } 1129 } 1130 1131 if ( $this->is_posts_page && ( ! isset( $q v['withcomments'] ) || ! $qv['withcomments'] ) ) {1127 $query_vars['post_status'] = preg_replace( '|[^a-z0-9_,-]|', '', $query_vars['post_status'] ); 1128 } 1129 } 1130 1131 if ( $this->is_posts_page && ( ! isset( $query_vars['withcomments'] ) || ! $query_vars['withcomments'] ) ) { 1132 1132 $this->is_comment_feed = false; 1133 1133 } … … 1136 1136 // Done correcting `is_*` for 'page_on_front' and 'page_for_posts'. 1137 1137 1138 if ( '404' == $q v['error'] ) {1138 if ( '404' == $query_vars['error'] ) { 1139 1139 $this->set_404(); 1140 1140 } … … 1162 1162 * @since 3.1.0 1163 1163 * 1164 * @param array $q The query variables. Passed by reference.1165 */ 1166 public function parse_tax_query( &$q ) {1167 if ( ! empty( $q ['tax_query'] ) && is_array( $q['tax_query'] ) ) {1168 $tax_query = $q ['tax_query'];1164 * @param array $query_vars The query variables. Passed by reference. 1165 */ 1166 public function parse_tax_query( &$query_vars ) { 1167 if ( ! empty( $query_vars['tax_query'] ) && is_array( $query_vars['tax_query'] ) ) { 1168 $tax_query = $query_vars['tax_query']; 1169 1169 } else { 1170 1170 $tax_query = array(); 1171 1171 } 1172 1172 1173 if ( ! empty( $q ['taxonomy'] ) && ! empty( $q['term'] ) ) {1173 if ( ! empty( $query_vars['taxonomy'] ) && ! empty( $query_vars['term'] ) ) { 1174 1174 $tax_query[] = array( 1175 'taxonomy' => $q ['taxonomy'],1176 'terms' => array( $q ['term'] ),1175 'taxonomy' => $query_vars['taxonomy'], 1176 'terms' => array( $query_vars['term'] ), 1177 1177 'field' => 'slug', 1178 1178 ); … … 1184 1184 } 1185 1185 1186 if ( $t->query_var && ! empty( $q [ $t->query_var ] ) ) {1186 if ( $t->query_var && ! empty( $query_vars[ $t->query_var ] ) ) { 1187 1187 $tax_query_defaults = array( 1188 1188 'taxonomy' => $taxonomy, … … 1191 1191 1192 1192 if ( ! empty( $t->rewrite['hierarchical'] ) ) { 1193 $q [ $t->query_var ] = wp_basename( $q[ $t->query_var ] );1194 } 1195 1196 $term = $q [ $t->query_var ];1193 $query_vars[ $t->query_var ] = wp_basename( $query_vars[ $t->query_var ] ); 1194 } 1195 1196 $term = $query_vars[ $t->query_var ]; 1197 1197 1198 1198 if ( ! is_array( $term ) ) { … … 1225 1225 1226 1226 // If query string 'cat' is an array, implode it. 1227 if ( is_array( $q ['cat'] ) ) {1228 $q ['cat'] = implode( ',', $q['cat'] );1227 if ( is_array( $query_vars['cat'] ) ) { 1228 $query_vars['cat'] = implode( ',', $query_vars['cat'] ); 1229 1229 } 1230 1230 1231 1231 // Category stuff. 1232 1232 1233 if ( ! empty( $q ['cat'] ) && ! $this->is_singular ) {1233 if ( ! empty( $query_vars['cat'] ) && ! $this->is_singular ) { 1234 1234 $cat_in = array(); 1235 1235 $cat_not_in = array(); 1236 1236 1237 $cat_array = preg_split( '/[,\s]+/', urldecode( $q ['cat'] ) );1237 $cat_array = preg_split( '/[,\s]+/', urldecode( $query_vars['cat'] ) ); 1238 1238 $cat_array = array_map( 'intval', $cat_array ); 1239 1239 sort( $cat_array ); 1240 $q ['cat'] = implode( ',', $cat_array );1240 $query_vars['cat'] = implode( ',', $cat_array ); 1241 1241 1242 1242 foreach ( $cat_array as $cat ) { … … 1269 1269 } 1270 1270 1271 if ( ! empty( $q ['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) {1272 $q ['category__and'] = (array) $q['category__and'];1273 if ( ! isset( $q ['category__in'] ) ) {1274 $q ['category__in'] = array();1275 } 1276 $q ['category__in'][] = absint( reset( $q['category__and'] ) );1277 unset( $q ['category__and'] );1278 } 1279 1280 if ( ! empty( $q ['category__in'] ) ) {1281 $q ['category__in'] = array_map( 'absint', array_unique( (array) $q['category__in'] ) );1282 sort( $q ['category__in'] );1271 if ( ! empty( $query_vars['category__and'] ) && 1 === count( (array) $query_vars['category__and'] ) ) { 1272 $query_vars['category__and'] = (array) $query_vars['category__and']; 1273 if ( ! isset( $query_vars['category__in'] ) ) { 1274 $query_vars['category__in'] = array(); 1275 } 1276 $query_vars['category__in'][] = absint( reset( $query_vars['category__and'] ) ); 1277 unset( $query_vars['category__and'] ); 1278 } 1279 1280 if ( ! empty( $query_vars['category__in'] ) ) { 1281 $query_vars['category__in'] = array_map( 'absint', array_unique( (array) $query_vars['category__in'] ) ); 1282 sort( $query_vars['category__in'] ); 1283 1283 $tax_query[] = array( 1284 1284 'taxonomy' => 'category', 1285 'terms' => $q ['category__in'],1285 'terms' => $query_vars['category__in'], 1286 1286 'field' => 'term_id', 1287 1287 'include_children' => false, … … 1289 1289 } 1290 1290 1291 if ( ! empty( $q ['category__not_in'] ) ) {1292 $q ['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) );1293 sort( $q ['category__not_in'] );1291 if ( ! empty( $query_vars['category__not_in'] ) ) { 1292 $query_vars['category__not_in'] = array_map( 'absint', array_unique( (array) $query_vars['category__not_in'] ) ); 1293 sort( $query_vars['category__not_in'] ); 1294 1294 $tax_query[] = array( 1295 1295 'taxonomy' => 'category', 1296 'terms' => $q ['category__not_in'],1296 'terms' => $query_vars['category__not_in'], 1297 1297 'operator' => 'NOT IN', 1298 1298 'include_children' => false, … … 1300 1300 } 1301 1301 1302 if ( ! empty( $q ['category__and'] ) ) {1303 $q ['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) );1304 sort( $q ['category__and'] );1302 if ( ! empty( $query_vars['category__and'] ) ) { 1303 $query_vars['category__and'] = array_map( 'absint', array_unique( (array) $query_vars['category__and'] ) ); 1304 sort( $query_vars['category__and'] ); 1305 1305 $tax_query[] = array( 1306 1306 'taxonomy' => 'category', 1307 'terms' => $q ['category__and'],1307 'terms' => $query_vars['category__and'], 1308 1308 'field' => 'term_id', 1309 1309 'operator' => 'AND', … … 1313 1313 1314 1314 // If query string 'tag' is array, implode it. 1315 if ( is_array( $q ['tag'] ) ) {1316 $q ['tag'] = implode( ',', $q['tag'] );1315 if ( is_array( $query_vars['tag'] ) ) { 1316 $query_vars['tag'] = implode( ',', $query_vars['tag'] ); 1317 1317 } 1318 1318 1319 1319 // Tag stuff. 1320 1320 1321 if ( '' !== $q ['tag'] && ! $this->is_singular && $this->query_vars_changed ) {1322 if ( str_contains( $q ['tag'], ',' ) ) {1321 if ( '' !== $query_vars['tag'] && ! $this->is_singular && $this->query_vars_changed ) { 1322 if ( str_contains( $query_vars['tag'], ',' ) ) { 1323 1323 // @todo Handle normalizing `tag` query string. 1324 $tags = preg_split( '/[,\r\n\t ]+/', $q ['tag'] );1324 $tags = preg_split( '/[,\r\n\t ]+/', $query_vars['tag'] ); 1325 1325 foreach ( (array) $tags as $tag ) { 1326 $tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' );1327 $q ['tag_slug__in'][] = $tag;1328 sort( $q ['tag_slug__in'] );1329 } 1330 } elseif ( preg_match( '/[+\r\n\t ]+/', $q ['tag'] ) || ! empty( $q['cat'] ) ) {1331 $tags = preg_split( '/[+\r\n\t ]+/', $q ['tag'] );1326 $tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' ); 1327 $query_vars['tag_slug__in'][] = $tag; 1328 sort( $query_vars['tag_slug__in'] ); 1329 } 1330 } elseif ( preg_match( '/[+\r\n\t ]+/', $query_vars['tag'] ) || ! empty( $query_vars['cat'] ) ) { 1331 $tags = preg_split( '/[+\r\n\t ]+/', $query_vars['tag'] ); 1332 1332 foreach ( (array) $tags as $tag ) { 1333 $tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' );1334 $q ['tag_slug__and'][] = $tag;1333 $tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' ); 1334 $query_vars['tag_slug__and'][] = $tag; 1335 1335 } 1336 1336 } else { 1337 $q['tag'] = sanitize_term_field( 'slug', $q['tag'], 0, 'post_tag', 'db' ); 1338 $q['tag_slug__in'][] = $q['tag']; 1339 sort( $q['tag_slug__in'] ); 1340 } 1341 } 1342 1343 if ( ! empty( $q['tag_id'] ) ) { 1344 $q['tag_id'] = absint( $q['tag_id'] ); 1337 $query_vars['tag'] = sanitize_term_field( 'slug', $query_vars['tag'], 0, 'post_tag', 'db' ); 1338 $query_vars['tag_slug__in'][] = $query_vars['tag']; 1339 sort( $query_vars['tag_slug__in'] ); 1340 } 1341 } 1342 1343 if ( ! empty( $query_vars['tag_id'] ) ) { 1344 $query_vars['tag_id'] = absint( $query_vars['tag_id'] ); 1345 $tax_query[] = array( 1346 'taxonomy' => 'post_tag', 1347 'terms' => $query_vars['tag_id'], 1348 ); 1349 } 1350 1351 if ( ! empty( $query_vars['tag__in'] ) ) { 1352 $query_vars['tag__in'] = array_map( 'absint', array_unique( (array) $query_vars['tag__in'] ) ); 1353 sort( $query_vars['tag__in'] ); 1345 1354 $tax_query[] = array( 1346 1355 'taxonomy' => 'post_tag', 1347 'terms' => $q ['tag_id'],1356 'terms' => $query_vars['tag__in'], 1348 1357 ); 1349 1358 } 1350 1359 1351 if ( ! empty( $q ['tag__in'] ) ) {1352 $q ['tag__in'] = array_map( 'absint', array_unique( (array) $q['tag__in'] ) );1353 sort( $q ['tag__in'] );1360 if ( ! empty( $query_vars['tag__not_in'] ) ) { 1361 $query_vars['tag__not_in'] = array_map( 'absint', array_unique( (array) $query_vars['tag__not_in'] ) ); 1362 sort( $query_vars['tag__not_in'] ); 1354 1363 $tax_query[] = array( 1355 1364 'taxonomy' => 'post_tag', 1356 'terms' => $q['tag__in'], 1365 'terms' => $query_vars['tag__not_in'], 1366 'operator' => 'NOT IN', 1357 1367 ); 1358 1368 } 1359 1369 1360 if ( ! empty( $q ['tag__not_in'] ) ) {1361 $q ['tag__not_in'] = array_map( 'absint', array_unique( (array) $q['tag__not_in'] ) );1362 sort( $q ['tag__not_in'] );1370 if ( ! empty( $query_vars['tag__and'] ) ) { 1371 $query_vars['tag__and'] = array_map( 'absint', array_unique( (array) $query_vars['tag__and'] ) ); 1372 sort( $query_vars['tag__and'] ); 1363 1373 $tax_query[] = array( 1364 1374 'taxonomy' => 'post_tag', 1365 'terms' => $q ['tag__not_in'],1366 'operator' => ' NOT IN',1375 'terms' => $query_vars['tag__and'], 1376 'operator' => 'AND', 1367 1377 ); 1368 1378 } 1369 1379 1370 if ( ! empty( $q ['tag__and'] ) ) {1371 $q ['tag__and'] = array_map( 'absint', array_unique( (array) $q['tag__and'] ) );1372 sort( $q ['tag__and'] );1380 if ( ! empty( $query_vars['tag_slug__in'] ) ) { 1381 $query_vars['tag_slug__in'] = array_map( 'sanitize_title_for_query', array_unique( (array) $query_vars['tag_slug__in'] ) ); 1382 sort( $query_vars['tag_slug__in'] ); 1373 1383 $tax_query[] = array( 1374 1384 'taxonomy' => 'post_tag', 1375 'terms' => $q ['tag__and'],1376 ' operator' => 'AND',1385 'terms' => $query_vars['tag_slug__in'], 1386 'field' => 'slug', 1377 1387 ); 1378 1388 } 1379 1389 1380 if ( ! empty( $q ['tag_slug__in'] ) ) {1381 $q ['tag_slug__in'] = array_map( 'sanitize_title_for_query', array_unique( (array) $q['tag_slug__in'] ) );1382 sort( $q ['tag_slug__in'] );1390 if ( ! empty( $query_vars['tag_slug__and'] ) ) { 1391 $query_vars['tag_slug__and'] = array_map( 'sanitize_title_for_query', array_unique( (array) $query_vars['tag_slug__and'] ) ); 1392 sort( $query_vars['tag_slug__and'] ); 1383 1393 $tax_query[] = array( 1384 1394 'taxonomy' => 'post_tag', 1385 'terms' => $q['tag_slug__in'], 1386 'field' => 'slug', 1387 ); 1388 } 1389 1390 if ( ! empty( $q['tag_slug__and'] ) ) { 1391 $q['tag_slug__and'] = array_map( 'sanitize_title_for_query', array_unique( (array) $q['tag_slug__and'] ) ); 1392 sort( $q['tag_slug__and'] ); 1393 $tax_query[] = array( 1394 'taxonomy' => 'post_tag', 1395 'terms' => $q['tag_slug__and'], 1395 'terms' => $query_vars['tag_slug__and'], 1396 1396 'field' => 'slug', 1397 1397 'operator' => 'AND', … … 1418 1418 * @global wpdb $wpdb WordPress database abstraction object. 1419 1419 * 1420 * @param array $q Query variables.1420 * @param array $query_vars Query variables. 1421 1421 * @return string WHERE clause. 1422 1422 */ 1423 protected function parse_search( &$q ) {1423 protected function parse_search( &$query_vars ) { 1424 1424 global $wpdb; 1425 1425 … … 1427 1427 1428 1428 // Added slashes screw with quote grouping when done early, so done later. 1429 $q ['s'] = stripslashes( $q['s'] );1429 $query_vars['s'] = stripslashes( $query_vars['s'] ); 1430 1430 if ( empty( $_GET['s'] ) && $this->is_main_query() ) { 1431 $q ['s'] = urldecode( $q['s'] );1431 $query_vars['s'] = urldecode( $query_vars['s'] ); 1432 1432 } 1433 1433 // There are no line breaks in <input /> fields. 1434 $q ['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] );1435 $q ['search_terms_count'] = 1;1436 if ( ! empty( $q ['sentence'] ) ) {1437 $q ['search_terms'] = array( $q['s'] );1434 $query_vars['s'] = str_replace( array( "\r", "\n" ), '', $query_vars['s'] ); 1435 $query_vars['search_terms_count'] = 1; 1436 if ( ! empty( $query_vars['sentence'] ) ) { 1437 $query_vars['search_terms'] = array( $query_vars['s'] ); 1438 1438 } else { 1439 if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q ['s'], $matches ) ) {1440 $q ['search_terms_count'] = count( $matches[0] );1441 $q ['search_terms'] = $this->parse_search_terms( $matches[0] );1439 if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $query_vars['s'], $matches ) ) { 1440 $query_vars['search_terms_count'] = count( $matches[0] ); 1441 $query_vars['search_terms'] = $this->parse_search_terms( $matches[0] ); 1442 1442 // If the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence. 1443 if ( empty( $q ['search_terms'] ) || count( $q['search_terms'] ) > 9 ) {1444 $q ['search_terms'] = array( $q['s'] );1443 if ( empty( $query_vars['search_terms'] ) || count( $query_vars['search_terms'] ) > 9 ) { 1444 $query_vars['search_terms'] = array( $query_vars['s'] ); 1445 1445 } 1446 1446 } else { 1447 $q ['search_terms'] = array( $q['s'] );1448 } 1449 } 1450 1451 $n = ! empty( $q['exact'] ) ? '' : '%';1452 $searchand = '';1453 $q ['search_orderby_title'] = array();1447 $query_vars['search_terms'] = array( $query_vars['s'] ); 1448 } 1449 } 1450 1451 $n = ! empty( $query_vars['exact'] ) ? '' : '%'; 1452 $searchand = ''; 1453 $query_vars['search_orderby_title'] = array(); 1454 1454 1455 1455 $default_search_columns = array( 'post_title', 'post_excerpt', 'post_content' ); 1456 $search_columns = ! empty( $q ['search_columns'] ) ? $q['search_columns'] : $default_search_columns;1456 $search_columns = ! empty( $query_vars['search_columns'] ) ? $query_vars['search_columns'] : $default_search_columns; 1457 1457 if ( ! is_array( $search_columns ) ) { 1458 1458 $search_columns = array( $search_columns ); … … 1471 1471 * @param WP_Query $query The current WP_Query instance. 1472 1472 */ 1473 $search_columns = (array) apply_filters( 'post_search_columns', $search_columns, $q ['s'], $this );1473 $search_columns = (array) apply_filters( 'post_search_columns', $search_columns, $query_vars['s'], $this ); 1474 1474 1475 1475 // Use only supported search columns. … … 1489 1489 $exclusion_prefix = apply_filters( 'wp_query_search_exclusion_prefix', '-' ); 1490 1490 1491 foreach ( $q ['search_terms'] as $term ) {1491 foreach ( $query_vars['search_terms'] as $term ) { 1492 1492 // If there is an $exclusion_prefix, terms prefixed with it should be excluded. 1493 1493 $exclude = $exclusion_prefix && str_starts_with( $term, $exclusion_prefix ); … … 1502 1502 1503 1503 if ( $n && ! $exclude ) { 1504 $like = '%' . $wpdb->esc_like( $term ) . '%';1505 $q ['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like );1504 $like = '%' . $wpdb->esc_like( $term ) . '%'; 1505 $query_vars['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like ); 1506 1506 } 1507 1507 … … 1624 1624 * @global wpdb $wpdb WordPress database abstraction object. 1625 1625 * 1626 * @param array $q Query variables.1626 * @param array $query_vars Query variables. 1627 1627 * @return string ORDER BY clause. 1628 1628 */ 1629 protected function parse_search_order( &$q ) {1629 protected function parse_search_order( &$query_vars ) { 1630 1630 global $wpdb; 1631 1631 1632 if ( $q ['search_terms_count'] > 1 ) {1633 $num_terms = count( $q ['search_orderby_title'] );1632 if ( $query_vars['search_terms_count'] > 1 ) { 1633 $num_terms = count( $query_vars['search_orderby_title'] ); 1634 1634 1635 1635 // If the search terms contain negative queries, don't bother ordering by sentence matches. 1636 1636 $like = ''; 1637 if ( ! preg_match( '/(?:\s|^)\-/', $q ['s'] ) ) {1638 $like = '%' . $wpdb->esc_like( $q ['s'] ) . '%';1637 if ( ! preg_match( '/(?:\s|^)\-/', $query_vars['s'] ) ) { 1638 $like = '%' . $wpdb->esc_like( $query_vars['s'] ) . '%'; 1639 1639 } 1640 1640 … … 1652 1652 if ( $num_terms < 7 ) { 1653 1653 // All words in title. 1654 $search_orderby .= 'WHEN ' . implode( ' AND ', $q ['search_orderby_title'] ) . ' THEN 2 ';1654 $search_orderby .= 'WHEN ' . implode( ' AND ', $query_vars['search_orderby_title'] ) . ' THEN 2 '; 1655 1655 // Any word in title, not needed when $num_terms == 1. 1656 1656 if ( $num_terms > 1 ) { 1657 $search_orderby .= 'WHEN ' . implode( ' OR ', $q ['search_orderby_title'] ) . ' THEN 3 ';1657 $search_orderby .= 'WHEN ' . implode( ' OR ', $query_vars['search_orderby_title'] ) . ' THEN 3 '; 1658 1658 } 1659 1659 } … … 1670 1670 } else { 1671 1671 // Single word or sentence search. 1672 $search_orderby = reset( $q ['search_orderby_title'] ) . ' DESC';1672 $search_orderby = reset( $query_vars['search_orderby_title'] ) . ' DESC'; 1673 1673 } 1674 1674 … … 1910 1910 do_action_ref_array( 'pre_get_posts', array( &$this ) ); 1911 1911 1912 // Shorthand.1913 $q = &$this->query_vars;1912 // Locally scoped reference for easy of use. 1913 $query_vars = &$this->query_vars; 1914 1914 1915 1915 // Fill again in case 'pre_get_posts' unset some vars. 1916 $q = $this->fill_query_vars( $q);1916 $query_vars = $this->fill_query_vars( $query_vars ); 1917 1917 1918 1918 /** … … 1928 1928 // Parse meta query. 1929 1929 $this->meta_query = new WP_Meta_Query(); 1930 $this->meta_query->parse_query_vars( $q );1930 $this->meta_query->parse_query_vars( $query_vars ); 1931 1931 1932 1932 // Set a flag if a 'pre_get_posts' hook changed the query vars. … … 1950 1950 $page = 1; 1951 1951 1952 if ( isset( $q ['caller_get_posts'] ) ) {1952 if ( isset( $query_vars['caller_get_posts'] ) ) { 1953 1953 _deprecated_argument( 1954 1954 'WP_Query', … … 1962 1962 ); 1963 1963 1964 if ( ! isset( $q ['ignore_sticky_posts'] ) ) {1965 $q ['ignore_sticky_posts'] = $q['caller_get_posts'];1966 } 1967 } 1968 1969 if ( ! isset( $q ['ignore_sticky_posts'] ) ) {1970 $q ['ignore_sticky_posts'] = false;1971 } 1972 1973 if ( ! isset( $q ['suppress_filters'] ) ) {1974 $q ['suppress_filters'] = false;1975 } 1976 1977 if ( ! isset( $q ['cache_results'] ) ) {1978 $q ['cache_results'] = true;1979 } 1980 1981 if ( ! isset( $q ['update_post_term_cache'] ) ) {1982 $q ['update_post_term_cache'] = true;1983 } 1984 1985 if ( ! isset( $q ['update_menu_item_cache'] ) ) {1986 $q ['update_menu_item_cache'] = false;1987 } 1988 1989 if ( ! isset( $q ['lazy_load_term_meta'] ) ) {1990 $q ['lazy_load_term_meta'] = $q['update_post_term_cache'];1991 } elseif ( $q ['lazy_load_term_meta'] ) { // Lazy loading term meta only works if term caches are primed.1992 $q ['update_post_term_cache'] = true;1993 } 1994 1995 if ( ! isset( $q ['update_post_meta_cache'] ) ) {1996 $q ['update_post_meta_cache'] = true;1997 } 1998 1999 if ( ! isset( $q ['post_type'] ) ) {1964 if ( ! isset( $query_vars['ignore_sticky_posts'] ) ) { 1965 $query_vars['ignore_sticky_posts'] = $query_vars['caller_get_posts']; 1966 } 1967 } 1968 1969 if ( ! isset( $query_vars['ignore_sticky_posts'] ) ) { 1970 $query_vars['ignore_sticky_posts'] = false; 1971 } 1972 1973 if ( ! isset( $query_vars['suppress_filters'] ) ) { 1974 $query_vars['suppress_filters'] = false; 1975 } 1976 1977 if ( ! isset( $query_vars['cache_results'] ) ) { 1978 $query_vars['cache_results'] = true; 1979 } 1980 1981 if ( ! isset( $query_vars['update_post_term_cache'] ) ) { 1982 $query_vars['update_post_term_cache'] = true; 1983 } 1984 1985 if ( ! isset( $query_vars['update_menu_item_cache'] ) ) { 1986 $query_vars['update_menu_item_cache'] = false; 1987 } 1988 1989 if ( ! isset( $query_vars['lazy_load_term_meta'] ) ) { 1990 $query_vars['lazy_load_term_meta'] = $query_vars['update_post_term_cache']; 1991 } elseif ( $query_vars['lazy_load_term_meta'] ) { // Lazy loading term meta only works if term caches are primed. 1992 $query_vars['update_post_term_cache'] = true; 1993 } 1994 1995 if ( ! isset( $query_vars['update_post_meta_cache'] ) ) { 1996 $query_vars['update_post_meta_cache'] = true; 1997 } 1998 1999 if ( ! isset( $query_vars['post_type'] ) ) { 2000 2000 if ( $this->is_search ) { 2001 $q ['post_type'] = 'any';2001 $query_vars['post_type'] = 'any'; 2002 2002 } else { 2003 $q ['post_type'] = '';2004 } 2005 } 2006 $post_type = $q ['post_type'];2007 if ( empty( $q ['posts_per_page'] ) ) {2008 $q ['posts_per_page'] = get_option( 'posts_per_page' );2009 } 2010 if ( isset( $q ['showposts'] ) && $q['showposts'] ) {2011 $q ['showposts'] = (int) $q['showposts'];2012 $q ['posts_per_page'] = $q['showposts'];2013 } 2014 if ( ( isset( $q ['posts_per_archive_page'] ) && 0 != $q['posts_per_archive_page'] ) && ( $this->is_archive || $this->is_search ) ) {2015 $q ['posts_per_page'] = $q['posts_per_archive_page'];2016 } 2017 if ( ! isset( $q ['nopaging'] ) ) {2018 if ( -1 == $q ['posts_per_page'] ) {2019 $q ['nopaging'] = true;2003 $query_vars['post_type'] = ''; 2004 } 2005 } 2006 $post_type = $query_vars['post_type']; 2007 if ( empty( $query_vars['posts_per_page'] ) ) { 2008 $query_vars['posts_per_page'] = get_option( 'posts_per_page' ); 2009 } 2010 if ( isset( $query_vars['showposts'] ) && $query_vars['showposts'] ) { 2011 $query_vars['showposts'] = (int) $query_vars['showposts']; 2012 $query_vars['posts_per_page'] = $query_vars['showposts']; 2013 } 2014 if ( ( isset( $query_vars['posts_per_archive_page'] ) && 0 != $query_vars['posts_per_archive_page'] ) && ( $this->is_archive || $this->is_search ) ) { 2015 $query_vars['posts_per_page'] = $query_vars['posts_per_archive_page']; 2016 } 2017 if ( ! isset( $query_vars['nopaging'] ) ) { 2018 if ( -1 == $query_vars['posts_per_page'] ) { 2019 $query_vars['nopaging'] = true; 2020 2020 } else { 2021 $q ['nopaging'] = false;2021 $query_vars['nopaging'] = false; 2022 2022 } 2023 2023 } … … 2025 2025 if ( $this->is_feed ) { 2026 2026 // This overrides 'posts_per_page'. 2027 if ( ! empty( $q ['posts_per_rss'] ) ) {2028 $q ['posts_per_page'] = $q['posts_per_rss'];2027 if ( ! empty( $query_vars['posts_per_rss'] ) ) { 2028 $query_vars['posts_per_page'] = $query_vars['posts_per_rss']; 2029 2029 } else { 2030 $q ['posts_per_page'] = get_option( 'posts_per_rss' );2031 } 2032 $q ['nopaging'] = false;2033 } 2034 2035 $q ['posts_per_page'] = (int) $q['posts_per_page'];2036 if ( $q ['posts_per_page'] < -1 ) {2037 $q ['posts_per_page'] = abs( $q['posts_per_page'] );2038 } elseif ( 0 === $q ['posts_per_page'] ) {2039 $q ['posts_per_page'] = 1;2040 } 2041 2042 if ( ! isset( $q ['comments_per_page'] ) || 0 == $q['comments_per_page'] ) {2043 $q ['comments_per_page'] = get_option( 'comments_per_page' );2044 } 2045 2046 if ( $this->is_home && ( empty( $this->query ) || 'true' === $q ['preview'] ) && ( 'page' === get_option( 'show_on_front' ) ) && get_option( 'page_on_front' ) ) {2047 $this->is_page = true;2048 $this->is_home = false;2049 $q ['page_id']= get_option( 'page_on_front' );2050 } 2051 2052 if ( isset( $q ['page'] ) ) {2053 $q ['page'] = is_scalar( $q['page'] ) ? absint( trim( $q['page'], '/' ) ) : 0;2030 $query_vars['posts_per_page'] = get_option( 'posts_per_rss' ); 2031 } 2032 $query_vars['nopaging'] = false; 2033 } 2034 2035 $query_vars['posts_per_page'] = (int) $query_vars['posts_per_page']; 2036 if ( $query_vars['posts_per_page'] < -1 ) { 2037 $query_vars['posts_per_page'] = abs( $query_vars['posts_per_page'] ); 2038 } elseif ( 0 === $query_vars['posts_per_page'] ) { 2039 $query_vars['posts_per_page'] = 1; 2040 } 2041 2042 if ( ! isset( $query_vars['comments_per_page'] ) || 0 == $query_vars['comments_per_page'] ) { 2043 $query_vars['comments_per_page'] = get_option( 'comments_per_page' ); 2044 } 2045 2046 if ( $this->is_home && ( empty( $this->query ) || 'true' === $query_vars['preview'] ) && ( 'page' === get_option( 'show_on_front' ) ) && get_option( 'page_on_front' ) ) { 2047 $this->is_page = true; 2048 $this->is_home = false; 2049 $query_vars['page_id'] = get_option( 'page_on_front' ); 2050 } 2051 2052 if ( isset( $query_vars['page'] ) ) { 2053 $query_vars['page'] = is_scalar( $query_vars['page'] ) ? absint( trim( $query_vars['page'], '/' ) ) : 0; 2054 2054 } 2055 2055 2056 2056 // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. 2057 if ( isset( $q ['no_found_rows'] ) ) {2058 $q ['no_found_rows'] = (bool) $q['no_found_rows'];2057 if ( isset( $query_vars['no_found_rows'] ) ) { 2058 $query_vars['no_found_rows'] = (bool) $query_vars['no_found_rows']; 2059 2059 } else { 2060 $q ['no_found_rows'] = false;2061 } 2062 2063 switch ( $q ['fields'] ) {2060 $query_vars['no_found_rows'] = false; 2061 } 2062 2063 switch ( $query_vars['fields'] ) { 2064 2064 case 'ids': 2065 2065 $fields = "{$wpdb->posts}.ID"; … … 2075 2075 * entire post object has been queried. 2076 2076 */ 2077 $q ['fields'] = 'all';2077 $query_vars['fields'] = 'all'; 2078 2078 // Falls through. 2079 2079 default: … … 2081 2081 } 2082 2082 2083 if ( '' !== $q ['menu_order'] ) {2084 $where .= " AND {$wpdb->posts}.menu_order = " . $q ['menu_order'];2083 if ( '' !== $query_vars['menu_order'] ) { 2084 $where .= " AND {$wpdb->posts}.menu_order = " . $query_vars['menu_order']; 2085 2085 } 2086 2086 // The "m" parameter is meant for months but accepts datetimes of varying specificity. 2087 if ( $q ['m'] ) {2088 $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr( $q ['m'], 0, 4 );2089 if ( strlen( $q ['m'] ) > 5 ) {2090 $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr( $q ['m'], 4, 2 );2091 } 2092 if ( strlen( $q ['m'] ) > 7 ) {2093 $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr( $q ['m'], 6, 2 );2094 } 2095 if ( strlen( $q ['m'] ) > 9 ) {2096 $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr( $q ['m'], 8, 2 );2097 } 2098 if ( strlen( $q ['m'] ) > 11 ) {2099 $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr( $q ['m'], 10, 2 );2100 } 2101 if ( strlen( $q ['m'] ) > 13 ) {2102 $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr( $q ['m'], 12, 2 );2087 if ( $query_vars['m'] ) { 2088 $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr( $query_vars['m'], 0, 4 ); 2089 if ( strlen( $query_vars['m'] ) > 5 ) { 2090 $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr( $query_vars['m'], 4, 2 ); 2091 } 2092 if ( strlen( $query_vars['m'] ) > 7 ) { 2093 $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr( $query_vars['m'], 6, 2 ); 2094 } 2095 if ( strlen( $query_vars['m'] ) > 9 ) { 2096 $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr( $query_vars['m'], 8, 2 ); 2097 } 2098 if ( strlen( $query_vars['m'] ) > 11 ) { 2099 $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr( $query_vars['m'], 10, 2 ); 2100 } 2101 if ( strlen( $query_vars['m'] ) > 13 ) { 2102 $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr( $query_vars['m'], 12, 2 ); 2103 2103 } 2104 2104 } … … 2107 2107 $date_parameters = array(); 2108 2108 2109 if ( '' !== $q ['hour'] ) {2110 $date_parameters['hour'] = $q ['hour'];2111 } 2112 2113 if ( '' !== $q ['minute'] ) {2114 $date_parameters['minute'] = $q ['minute'];2115 } 2116 2117 if ( '' !== $q ['second'] ) {2118 $date_parameters['second'] = $q ['second'];2119 } 2120 2121 if ( $q ['year'] ) {2122 $date_parameters['year'] = $q ['year'];2123 } 2124 2125 if ( $q ['monthnum'] ) {2126 $date_parameters['monthnum'] = $q ['monthnum'];2127 } 2128 2129 if ( $q ['w'] ) {2130 $date_parameters['week'] = $q ['w'];2131 } 2132 2133 if ( $q ['day'] ) {2134 $date_parameters['day'] = $q ['day'];2109 if ( '' !== $query_vars['hour'] ) { 2110 $date_parameters['hour'] = $query_vars['hour']; 2111 } 2112 2113 if ( '' !== $query_vars['minute'] ) { 2114 $date_parameters['minute'] = $query_vars['minute']; 2115 } 2116 2117 if ( '' !== $query_vars['second'] ) { 2118 $date_parameters['second'] = $query_vars['second']; 2119 } 2120 2121 if ( $query_vars['year'] ) { 2122 $date_parameters['year'] = $query_vars['year']; 2123 } 2124 2125 if ( $query_vars['monthnum'] ) { 2126 $date_parameters['monthnum'] = $query_vars['monthnum']; 2127 } 2128 2129 if ( $query_vars['w'] ) { 2130 $date_parameters['week'] = $query_vars['w']; 2131 } 2132 2133 if ( $query_vars['day'] ) { 2134 $date_parameters['day'] = $query_vars['day']; 2135 2135 } 2136 2136 … … 2142 2142 2143 2143 // Handle complex date queries. 2144 if ( ! empty( $q ['date_query'] ) ) {2145 $this->date_query = new WP_Date_Query( $q ['date_query'] );2144 if ( ! empty( $query_vars['date_query'] ) ) { 2145 $this->date_query = new WP_Date_Query( $query_vars['date_query'] ); 2146 2146 $where .= $this->date_query->get_sql(); 2147 2147 } 2148 2148 2149 2149 // If we've got a post_type AND it's not "any" post_type. 2150 if ( ! empty( $q ['post_type'] ) && 'any' !== $q['post_type'] ) {2151 foreach ( (array) $q ['post_type'] as $_post_type ) {2150 if ( ! empty( $query_vars['post_type'] ) && 'any' !== $query_vars['post_type'] ) { 2151 foreach ( (array) $query_vars['post_type'] as $_post_type ) { 2152 2152 $ptype_obj = get_post_type_object( $_post_type ); 2153 if ( ! $ptype_obj || ! $ptype_obj->query_var || empty( $q [ $ptype_obj->query_var ] ) ) {2153 if ( ! $ptype_obj || ! $ptype_obj->query_var || empty( $query_vars[ $ptype_obj->query_var ] ) ) { 2154 2154 continue; 2155 2155 } … … 2157 2157 if ( ! $ptype_obj->hierarchical ) { 2158 2158 // Non-hierarchical post types can directly use 'name'. 2159 $q ['name'] = $q[ $ptype_obj->query_var ];2159 $query_vars['name'] = $query_vars[ $ptype_obj->query_var ]; 2160 2160 } else { 2161 2161 // Hierarchical post types will operate through 'pagename'. 2162 $q ['pagename'] = $q[ $ptype_obj->query_var ];2163 $q ['name'] = '';2162 $query_vars['pagename'] = $query_vars[ $ptype_obj->query_var ]; 2163 $query_vars['name'] = ''; 2164 2164 } 2165 2165 … … 2170 2170 } 2171 2171 2172 if ( '' !== $q ['title'] ) {2173 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q ['title'] ) );2172 if ( '' !== $query_vars['title'] ) { 2173 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $query_vars['title'] ) ); 2174 2174 } 2175 2175 2176 2176 // Parameters related to 'post_name'. 2177 if ( '' !== $q ['name'] ) {2178 $q ['name'] = sanitize_title_for_query( $q['name'] );2179 $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";2180 } elseif ( '' !== $q ['pagename'] ) {2177 if ( '' !== $query_vars['name'] ) { 2178 $query_vars['name'] = sanitize_title_for_query( $query_vars['name'] ); 2179 $where .= " AND {$wpdb->posts}.post_name = '" . $query_vars['name'] . "'"; 2180 } elseif ( '' !== $query_vars['pagename'] ) { 2181 2181 if ( isset( $this->queried_object_id ) ) { 2182 2182 $reqpage = $this->queried_object_id; 2183 2183 } else { 2184 if ( 'page' !== $q ['post_type'] ) {2185 foreach ( (array) $q ['post_type'] as $_post_type ) {2184 if ( 'page' !== $query_vars['post_type'] ) { 2185 foreach ( (array) $query_vars['post_type'] as $_post_type ) { 2186 2186 $ptype_obj = get_post_type_object( $_post_type ); 2187 2187 if ( ! $ptype_obj || ! $ptype_obj->hierarchical ) { … … 2189 2189 } 2190 2190 2191 $reqpage = get_page_by_path( $q ['pagename'], OBJECT, $_post_type );2191 $reqpage = get_page_by_path( $query_vars['pagename'], OBJECT, $_post_type ); 2192 2192 if ( $reqpage ) { 2193 2193 break; … … 2196 2196 unset( $ptype_obj ); 2197 2197 } else { 2198 $reqpage = get_page_by_path( $q ['pagename'] );2198 $reqpage = get_page_by_path( $query_vars['pagename'] ); 2199 2199 } 2200 2200 if ( ! empty( $reqpage ) ) { … … 2207 2207 $page_for_posts = get_option( 'page_for_posts' ); 2208 2208 if ( ( 'page' !== get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) { 2209 $q ['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) );2210 $q ['name'] = $q['pagename'];2211 $where .= " AND ({$wpdb->posts}.ID = '$reqpage')";2212 $reqpage_obj = get_post( $reqpage );2209 $query_vars['pagename'] = sanitize_title_for_query( wp_basename( $query_vars['pagename'] ) ); 2210 $query_vars['name'] = $query_vars['pagename']; 2211 $where .= " AND ({$wpdb->posts}.ID = '$reqpage')"; 2212 $reqpage_obj = get_post( $reqpage ); 2213 2213 if ( is_object( $reqpage_obj ) && 'attachment' === $reqpage_obj->post_type ) { 2214 $this->is_attachment = true;2215 $post_type = 'attachment';2216 $q ['post_type']= 'attachment';2217 $this->is_page = true;2218 $q ['attachment_id']= $reqpage;2219 } 2220 } 2221 } elseif ( '' !== $q ['attachment'] ) {2222 $q ['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) );2223 $q ['name'] = $q['attachment'];2224 $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'";2225 } elseif ( is_array( $q ['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) {2226 $q ['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] );2214 $this->is_attachment = true; 2215 $post_type = 'attachment'; 2216 $query_vars['post_type'] = 'attachment'; 2217 $this->is_page = true; 2218 $query_vars['attachment_id'] = $reqpage; 2219 } 2220 } 2221 } elseif ( '' !== $query_vars['attachment'] ) { 2222 $query_vars['attachment'] = sanitize_title_for_query( wp_basename( $query_vars['attachment'] ) ); 2223 $query_vars['name'] = $query_vars['attachment']; 2224 $where .= " AND {$wpdb->posts}.post_name = '" . $query_vars['attachment'] . "'"; 2225 } elseif ( is_array( $query_vars['post_name__in'] ) && ! empty( $query_vars['post_name__in'] ) ) { 2226 $query_vars['post_name__in'] = array_map( 'sanitize_title_for_query', $query_vars['post_name__in'] ); 2227 2227 // Duplicate array before sorting to allow for the orderby clause. 2228 $post_name__in_for_where = array_unique( $q ['post_name__in'] );2228 $post_name__in_for_where = array_unique( $query_vars['post_name__in'] ); 2229 2229 sort( $post_name__in_for_where ); 2230 2230 $post_name__in = "'" . implode( "','", $post_name__in_for_where ) . "'"; … … 2233 2233 2234 2234 // If an attachment is requested by number, let it supersede any post number. 2235 if ( $q ['attachment_id'] ) {2236 $q ['p'] = absint( $q['attachment_id'] );2235 if ( $query_vars['attachment_id'] ) { 2236 $query_vars['p'] = absint( $query_vars['attachment_id'] ); 2237 2237 } 2238 2238 2239 2239 // If a post number is specified, load that post. 2240 if ( $q ['p'] ) {2241 $where .= " AND {$wpdb->posts}.ID = " . $q ['p'];2242 } elseif ( $q ['post__in'] ) {2240 if ( $query_vars['p'] ) { 2241 $where .= " AND {$wpdb->posts}.ID = " . $query_vars['p']; 2242 } elseif ( $query_vars['post__in'] ) { 2243 2243 // Duplicate array before sorting to allow for the orderby clause. 2244 $post__in_for_where = $q ['post__in'];2244 $post__in_for_where = $query_vars['post__in']; 2245 2245 $post__in_for_where = array_unique( array_map( 'absint', $post__in_for_where ) ); 2246 2246 sort( $post__in_for_where ); 2247 2247 $post__in = implode( ',', array_map( 'absint', $post__in_for_where ) ); 2248 2248 $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; 2249 } elseif ( $q ['post__not_in'] ) {2250 sort( $q ['post__not_in'] );2251 $post__not_in = implode( ',', array_map( 'absint', $q ['post__not_in'] ) );2249 } elseif ( $query_vars['post__not_in'] ) { 2250 sort( $query_vars['post__not_in'] ); 2251 $post__not_in = implode( ',', array_map( 'absint', $query_vars['post__not_in'] ) ); 2252 2252 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; 2253 2253 } 2254 2254 2255 if ( is_numeric( $q ['post_parent'] ) ) {2256 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $q ['post_parent'] );2257 } elseif ( $q ['post_parent__in'] ) {2255 if ( is_numeric( $query_vars['post_parent'] ) ) { 2256 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $query_vars['post_parent'] ); 2257 } elseif ( $query_vars['post_parent__in'] ) { 2258 2258 // Duplicate array before sorting to allow for the orderby clause. 2259 $post_parent__in_for_where = $q ['post_parent__in'];2259 $post_parent__in_for_where = $query_vars['post_parent__in']; 2260 2260 $post_parent__in_for_where = array_unique( array_map( 'absint', $post_parent__in_for_where ) ); 2261 2261 sort( $post_parent__in_for_where ); 2262 2262 $post_parent__in = implode( ',', array_map( 'absint', $post_parent__in_for_where ) ); 2263 2263 $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; 2264 } elseif ( $q ['post_parent__not_in'] ) {2265 sort( $q ['post_parent__not_in'] );2266 $post_parent__not_in = implode( ',', array_map( 'absint', $q ['post_parent__not_in'] ) );2264 } elseif ( $query_vars['post_parent__not_in'] ) { 2265 sort( $query_vars['post_parent__not_in'] ); 2266 $post_parent__not_in = implode( ',', array_map( 'absint', $query_vars['post_parent__not_in'] ) ); 2267 2267 $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; 2268 2268 } 2269 2269 2270 if ( $q ['page_id'] ) {2271 if ( ( 'page' !== get_option( 'show_on_front' ) ) || ( get_option( 'page_for_posts' ) != $q ['page_id'] ) ) {2272 $q ['p'] = $q['page_id'];2273 $where = " AND {$wpdb->posts}.ID = " . $q['page_id'];2270 if ( $query_vars['page_id'] ) { 2271 if ( ( 'page' !== get_option( 'show_on_front' ) ) || ( get_option( 'page_for_posts' ) != $query_vars['page_id'] ) ) { 2272 $query_vars['p'] = $query_vars['page_id']; 2273 $where = " AND {$wpdb->posts}.ID = " . $query_vars['page_id']; 2274 2274 } 2275 2275 } 2276 2276 2277 2277 // If a search pattern is specified, load the posts that match. 2278 if ( strlen( $q ['s'] ) ) {2279 $search = $this->parse_search( $q );2280 } 2281 2282 if ( ! $q ['suppress_filters'] ) {2278 if ( strlen( $query_vars['s'] ) ) { 2279 $search = $this->parse_search( $query_vars ); 2280 } 2281 2282 if ( ! $query_vars['suppress_filters'] ) { 2283 2283 /** 2284 2284 * Filters the search SQL that is used in the WHERE clause of WP_Query. … … 2294 2294 // Taxonomies. 2295 2295 if ( ! $this->is_singular ) { 2296 $this->parse_tax_query( $q );2296 $this->parse_tax_query( $query_vars ); 2297 2297 2298 2298 $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); … … 2338 2338 * first taxonomy other than 'post_tag' or 'category'. 2339 2339 */ 2340 if ( ! isset( $q ['taxonomy'] ) ) {2340 if ( ! isset( $query_vars['taxonomy'] ) ) { 2341 2341 foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { 2342 2342 if ( empty( $queried_items['terms'][0] ) ) { … … 2345 2345 2346 2346 if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ), true ) ) { 2347 $q ['taxonomy'] = $queried_taxonomy;2347 $query_vars['taxonomy'] = $queried_taxonomy; 2348 2348 2349 2349 if ( 'slug' === $queried_items['field'] ) { 2350 $q ['term'] = $queried_items['terms'][0];2350 $query_vars['term'] = $queried_items['terms'][0]; 2351 2351 } else { 2352 $q ['term_id'] = $queried_items['terms'][0];2352 $query_vars['term_id'] = $queried_items['terms'][0]; 2353 2353 } 2354 2354 … … 2390 2390 // Author/user stuff. 2391 2391 2392 if ( ! empty( $q ['author'] ) && '0' != $q['author'] ) {2393 $q ['author'] = addslashes_gpc( '' . urldecode( $q['author'] ) );2394 $authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $q['author'] ) ) );2392 if ( ! empty( $query_vars['author'] ) && '0' != $query_vars['author'] ) { 2393 $query_vars['author'] = addslashes_gpc( '' . urldecode( $query_vars['author'] ) ); 2394 $authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $query_vars['author'] ) ) ); 2395 2395 sort( $authors ); 2396 2396 foreach ( $authors as $author ) { 2397 $key = $author > 0 ? 'author__in' : 'author__not_in';2398 $q [ $key ][] = abs( $author );2399 } 2400 $q ['author'] = implode( ',', $authors );2401 } 2402 2403 if ( ! empty( $q ['author__not_in'] ) ) {2404 if ( is_array( $q ['author__not_in'] ) ) {2405 $q ['author__not_in'] = array_unique( array_map( 'absint', $q['author__not_in'] ) );2406 sort( $q ['author__not_in'] );2407 } 2408 $author__not_in = implode( ',', (array) $q ['author__not_in'] );2397 $key = $author > 0 ? 'author__in' : 'author__not_in'; 2398 $query_vars[ $key ][] = abs( $author ); 2399 } 2400 $query_vars['author'] = implode( ',', $authors ); 2401 } 2402 2403 if ( ! empty( $query_vars['author__not_in'] ) ) { 2404 if ( is_array( $query_vars['author__not_in'] ) ) { 2405 $query_vars['author__not_in'] = array_unique( array_map( 'absint', $query_vars['author__not_in'] ) ); 2406 sort( $query_vars['author__not_in'] ); 2407 } 2408 $author__not_in = implode( ',', (array) $query_vars['author__not_in'] ); 2409 2409 $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) "; 2410 } elseif ( ! empty( $q ['author__in'] ) ) {2411 if ( is_array( $q ['author__in'] ) ) {2412 $q ['author__in'] = array_unique( array_map( 'absint', $q['author__in'] ) );2413 sort( $q ['author__in'] );2414 } 2415 $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q ['author__in'] ) ) );2410 } elseif ( ! empty( $query_vars['author__in'] ) ) { 2411 if ( is_array( $query_vars['author__in'] ) ) { 2412 $query_vars['author__in'] = array_unique( array_map( 'absint', $query_vars['author__in'] ) ); 2413 sort( $query_vars['author__in'] ); 2414 } 2415 $author__in = implode( ',', array_map( 'absint', array_unique( (array) $query_vars['author__in'] ) ) ); 2416 2416 $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; 2417 2417 } … … 2419 2419 // Author stuff for nice URLs. 2420 2420 2421 if ( '' !== $q ['author_name'] ) {2422 if ( str_contains( $q ['author_name'], '/' ) ) {2423 $q ['author_name'] = explode( '/', $q['author_name'] );2424 if ( $q ['author_name'][ count( $q['author_name'] ) - 1 ] ) {2425 $q ['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash.2421 if ( '' !== $query_vars['author_name'] ) { 2422 if ( str_contains( $query_vars['author_name'], '/' ) ) { 2423 $query_vars['author_name'] = explode( '/', $query_vars['author_name'] ); 2424 if ( $query_vars['author_name'][ count( $query_vars['author_name'] ) - 1 ] ) { 2425 $query_vars['author_name'] = $query_vars['author_name'][ count( $query_vars['author_name'] ) - 1 ]; // No trailing slash. 2426 2426 } else { 2427 $q ['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // There was a trailing slash.2428 } 2429 } 2430 $q ['author_name'] = sanitize_title_for_query( $q['author_name'] );2431 $q ['author'] = get_user_by( 'slug', $q['author_name'] );2432 if ( $q ['author'] ) {2433 $q ['author'] = $q['author']->ID;2434 } 2435 $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint( $q ['author'] ) . ')';2427 $query_vars['author_name'] = $query_vars['author_name'][ count( $query_vars['author_name'] ) - 2 ]; // There was a trailing slash. 2428 } 2429 } 2430 $query_vars['author_name'] = sanitize_title_for_query( $query_vars['author_name'] ); 2431 $query_vars['author'] = get_user_by( 'slug', $query_vars['author_name'] ); 2432 if ( $query_vars['author'] ) { 2433 $query_vars['author'] = $query_vars['author']->ID; 2434 } 2435 $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint( $query_vars['author'] ) . ')'; 2436 2436 } 2437 2437 2438 2438 // Matching by comment count. 2439 if ( isset( $q ['comment_count'] ) ) {2439 if ( isset( $query_vars['comment_count'] ) ) { 2440 2440 // Numeric comment count is converted to array format. 2441 if ( is_numeric( $q ['comment_count'] ) ) {2442 $q ['comment_count'] = array(2443 'value' => (int) $q ['comment_count'],2441 if ( is_numeric( $query_vars['comment_count'] ) ) { 2442 $query_vars['comment_count'] = array( 2443 'value' => (int) $query_vars['comment_count'], 2444 2444 ); 2445 2445 } 2446 2446 2447 if ( isset( $q ['comment_count']['value'] ) ) {2448 $q ['comment_count'] = array_merge(2447 if ( isset( $query_vars['comment_count']['value'] ) ) { 2448 $query_vars['comment_count'] = array_merge( 2449 2449 array( 2450 2450 'compare' => '=', 2451 2451 ), 2452 $q ['comment_count']2452 $query_vars['comment_count'] 2453 2453 ); 2454 2454 2455 2455 // Fallback for invalid compare operators is '='. 2456 2456 $compare_operators = array( '=', '!=', '>', '>=', '<', '<=' ); 2457 if ( ! in_array( $q ['comment_count']['compare'], $compare_operators, true ) ) {2458 $q ['comment_count']['compare'] = '=';2459 } 2460 2461 $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_count {$q ['comment_count']['compare']} %d", $q['comment_count']['value'] );2457 if ( ! in_array( $query_vars['comment_count']['compare'], $compare_operators, true ) ) { 2458 $query_vars['comment_count']['compare'] = '='; 2459 } 2460 2461 $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_count {$query_vars['comment_count']['compare']} %d", $query_vars['comment_count']['value'] ); 2462 2462 } 2463 2463 } … … 2465 2465 // MIME-Type stuff for attachment browsing. 2466 2466 2467 if ( isset( $q ['post_mime_type'] ) && '' !== $q['post_mime_type'] ) {2468 $whichmimetype = wp_post_mime_type_where( $q ['post_mime_type'], $wpdb->posts );2467 if ( isset( $query_vars['post_mime_type'] ) && '' !== $query_vars['post_mime_type'] ) { 2468 $whichmimetype = wp_post_mime_type_where( $query_vars['post_mime_type'], $wpdb->posts ); 2469 2469 } 2470 2470 $where .= $search . $whichauthor . $whichmimetype; … … 2480 2480 } 2481 2481 2482 $rand = ( isset( $q ['orderby'] ) && 'rand' === $q['orderby'] );2483 if ( ! isset( $q ['order'] ) ) {2484 $q ['order'] = $rand ? '' : 'DESC';2482 $rand = ( isset( $query_vars['orderby'] ) && 'rand' === $query_vars['orderby'] ); 2483 if ( ! isset( $query_vars['order'] ) ) { 2484 $query_vars['order'] = $rand ? '' : 'DESC'; 2485 2485 } else { 2486 $q ['order'] = $rand ? '' : $this->parse_order( $q['order'] );2486 $query_vars['order'] = $rand ? '' : $this->parse_order( $query_vars['order'] ); 2487 2487 } 2488 2488 2489 2489 // These values of orderby should ignore the 'order' parameter. 2490 2490 $force_asc = array( 'post__in', 'post_name__in', 'post_parent__in' ); 2491 if ( isset( $q ['orderby'] ) && in_array( $q['orderby'], $force_asc, true ) ) {2492 $q ['order'] = '';2491 if ( isset( $query_vars['orderby'] ) && in_array( $query_vars['orderby'], $force_asc, true ) ) { 2492 $query_vars['order'] = ''; 2493 2493 } 2494 2494 2495 2495 // Order by. 2496 if ( empty( $q ['orderby'] ) ) {2496 if ( empty( $query_vars['orderby'] ) ) { 2497 2497 /* 2498 2498 * Boolean false or empty array blanks out ORDER BY, 2499 2499 * while leaving the value unset or otherwise empty sets the default. 2500 2500 */ 2501 if ( isset( $q ['orderby'] ) && ( is_array( $q['orderby'] ) || false === $q['orderby'] ) ) {2501 if ( isset( $query_vars['orderby'] ) && ( is_array( $query_vars['orderby'] ) || false === $query_vars['orderby'] ) ) { 2502 2502 $orderby = ''; 2503 2503 } else { 2504 $orderby = "{$wpdb->posts}.post_date " . $q ['order'];2505 } 2506 } elseif ( 'none' === $q ['orderby'] ) {2504 $orderby = "{$wpdb->posts}.post_date " . $query_vars['order']; 2505 } 2506 } elseif ( 'none' === $query_vars['orderby'] ) { 2507 2507 $orderby = ''; 2508 2508 } else { 2509 2509 $orderby_array = array(); 2510 if ( is_array( $q ['orderby'] ) ) {2511 foreach ( $q ['orderby'] as $_orderby => $order ) {2510 if ( is_array( $query_vars['orderby'] ) ) { 2511 foreach ( $query_vars['orderby'] as $_orderby => $order ) { 2512 2512 $orderby = addslashes_gpc( urldecode( $_orderby ) ); 2513 2513 $parsed = $this->parse_orderby( $orderby ); … … 2522 2522 2523 2523 } else { 2524 $q ['orderby'] = urldecode( $q['orderby'] );2525 $q ['orderby'] = addslashes_gpc( $q['orderby'] );2526 2527 foreach ( explode( ' ', $q ['orderby'] ) as $i => $orderby ) {2524 $query_vars['orderby'] = urldecode( $query_vars['orderby'] ); 2525 $query_vars['orderby'] = addslashes_gpc( $query_vars['orderby'] ); 2526 2527 foreach ( explode( ' ', $query_vars['orderby'] ) as $i => $orderby ) { 2528 2528 $parsed = $this->parse_orderby( $orderby ); 2529 2529 // Only allow certain values for safety. … … 2534 2534 $orderby_array[] = $parsed; 2535 2535 } 2536 $orderby = implode( ' ' . $q ['order'] . ', ', $orderby_array );2536 $orderby = implode( ' ' . $query_vars['order'] . ', ', $orderby_array ); 2537 2537 2538 2538 if ( empty( $orderby ) ) { 2539 $orderby = "{$wpdb->posts}.post_date " . $q ['order'];2540 } elseif ( ! empty( $q ['order'] ) ) {2541 $orderby .= " {$q ['order']}";2539 $orderby = "{$wpdb->posts}.post_date " . $query_vars['order']; 2540 } elseif ( ! empty( $query_vars['order'] ) ) { 2541 $orderby .= " {$query_vars['order']}"; 2542 2542 } 2543 2543 } … … 2545 2545 2546 2546 // Order search results by relevance only when another "orderby" is not specified in the query. 2547 if ( ! empty( $q ['s'] ) ) {2547 if ( ! empty( $query_vars['s'] ) ) { 2548 2548 $search_orderby = ''; 2549 if ( ! empty( $q ['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) ) {2550 $search_orderby = $this->parse_search_order( $q );2551 } 2552 2553 if ( ! $q ['suppress_filters'] ) {2549 if ( ! empty( $query_vars['search_orderby_title'] ) && ( empty( $query_vars['orderby'] ) && ! $this->is_feed ) || ( isset( $query_vars['orderby'] ) && 'relevance' === $query_vars['orderby'] ) ) { 2550 $search_orderby = $this->parse_search_order( $query_vars ); 2551 } 2552 2553 if ( ! $query_vars['suppress_filters'] ) { 2554 2554 /** 2555 2555 * Filters the ORDER BY used when ordering search results. … … 2580 2580 } 2581 2581 2582 if ( isset( $q ['post_password'] ) ) {2583 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q ['post_password'] );2584 if ( empty( $q ['perm'] ) ) {2585 $q ['perm'] = 'readable';2586 } 2587 } elseif ( isset( $q ['has_password'] ) ) {2588 $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q ['has_password'] ? '!=' : '=' );2589 } 2590 2591 if ( ! empty( $q ['comment_status'] ) ) {2592 $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q ['comment_status'] );2593 } 2594 2595 if ( ! empty( $q ['ping_status'] ) ) {2596 $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q ['ping_status'] );2582 if ( isset( $query_vars['post_password'] ) ) { 2583 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $query_vars['post_password'] ); 2584 if ( empty( $query_vars['perm'] ) ) { 2585 $query_vars['perm'] = 'readable'; 2586 } 2587 } elseif ( isset( $query_vars['has_password'] ) ) { 2588 $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $query_vars['has_password'] ? '!=' : '=' ); 2589 } 2590 2591 if ( ! empty( $query_vars['comment_status'] ) ) { 2592 $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $query_vars['comment_status'] ); 2593 } 2594 2595 if ( ! empty( $query_vars['ping_status'] ) ) { 2596 $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $query_vars['ping_status'] ); 2597 2597 } 2598 2598 … … 2640 2640 if ( $skip_post_status ) { 2641 2641 $where .= $post_type_where; 2642 } elseif ( ! empty( $q ['post_status'] ) ) {2642 } elseif ( ! empty( $query_vars['post_status'] ) ) { 2643 2643 2644 2644 $where .= $post_type_where; 2645 2645 2646 2646 $statuswheres = array(); 2647 $q_status = $q ['post_status'];2647 $q_status = $query_vars['post_status']; 2648 2648 if ( ! is_array( $q_status ) ) { 2649 2649 $q_status = explode( ',', $q_status ); … … 2671 2671 } 2672 2672 2673 if ( empty( $q ['perm'] ) || 'readable' !== $q['perm'] ) {2673 if ( empty( $query_vars['perm'] ) || 'readable' !== $query_vars['perm'] ) { 2674 2674 $r_status = array_merge( $r_status, $p_status ); 2675 2675 unset( $p_status ); … … 2680 2680 } 2681 2681 if ( ! empty( $r_status ) ) { 2682 if ( ! empty( $q ['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) {2682 if ( ! empty( $query_vars['perm'] ) && 'editable' === $query_vars['perm'] && ! current_user_can( $edit_others_cap ) ) { 2683 2683 $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $r_status ) . '))'; 2684 2684 } else { … … 2687 2687 } 2688 2688 if ( ! empty( $p_status ) ) { 2689 if ( ! empty( $q ['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) {2689 if ( ! empty( $query_vars['perm'] ) && 'readable' === $query_vars['perm'] && ! current_user_can( $read_private_cap ) ) { 2690 2690 $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $p_status ) . '))'; 2691 2691 } else { … … 2773 2773 * manipulations to them are reflected in the paging by day queries. 2774 2774 */ 2775 if ( ! $q ['suppress_filters'] ) {2775 if ( ! $query_vars['suppress_filters'] ) { 2776 2776 /** 2777 2777 * Filters the WHERE clause of the query. … … 2796 2796 2797 2797 // Paging. 2798 if ( empty( $q ['nopaging'] ) && ! $this->is_singular ) {2799 $page = absint( $q ['paged'] );2798 if ( empty( $query_vars['nopaging'] ) && ! $this->is_singular ) { 2799 $page = absint( $query_vars['paged'] ); 2800 2800 if ( ! $page ) { 2801 2801 $page = 1; … … 2803 2803 2804 2804 // If 'offset' is provided, it takes precedence over 'paged'. 2805 if ( isset( $q ['offset'] ) && is_numeric( $q['offset'] ) ) {2806 $q ['offset'] = absint( $q['offset'] );2807 $pgstrt = $q['offset'] . ', ';2805 if ( isset( $query_vars['offset'] ) && is_numeric( $query_vars['offset'] ) ) { 2806 $query_vars['offset'] = absint( $query_vars['offset'] ); 2807 $pgstrt = $query_vars['offset'] . ', '; 2808 2808 } else { 2809 $pgstrt = absint( ( $page - 1 ) * $q ['posts_per_page'] ) . ', ';2810 } 2811 $limits = 'LIMIT ' . $pgstrt . $q ['posts_per_page'];2809 $pgstrt = absint( ( $page - 1 ) * $query_vars['posts_per_page'] ) . ', '; 2810 } 2811 $limits = 'LIMIT ' . $pgstrt . $query_vars['posts_per_page']; 2812 2812 } 2813 2813 … … 2824 2824 } 2825 2825 2826 if ( ! $q ['suppress_filters'] ) {2826 if ( ! $query_vars['suppress_filters'] ) { 2827 2827 /** 2828 2828 * Filters the JOIN clause of the comments feed query before sending. … … 2922 2922 * manipulate paging queries should use these hooks. 2923 2923 */ 2924 if ( ! $q ['suppress_filters'] ) {2924 if ( ! $query_vars['suppress_filters'] ) { 2925 2925 /** 2926 2926 * Filters the WHERE clause of the query. … … 3044 3044 * Regular plugins should use the hooks above. 3045 3045 */ 3046 if ( ! $q ['suppress_filters'] ) {3046 if ( ! $query_vars['suppress_filters'] ) { 3047 3047 /** 3048 3048 * Filters the WHERE clause of the query. … … 3171 3171 3172 3172 $found_rows = ''; 3173 if ( ! $q ['no_found_rows'] && ! empty( $limits ) ) {3173 if ( ! $query_vars['no_found_rows'] && ! empty( $limits ) ) { 3174 3174 $found_rows = 'SQL_CALC_FOUND_ROWS'; 3175 3175 } … … 3196 3196 $this->request = $old_request; 3197 3197 3198 if ( ! $q ['suppress_filters'] ) {3198 if ( ! $query_vars['suppress_filters'] ) { 3199 3199 /** 3200 3200 * Filters the completed SQL query before sending. … … 3255 3255 } 3256 3256 3257 if ( $q ['cache_results'] && $id_query_is_cacheable ) {3257 if ( $query_vars['cache_results'] && $id_query_is_cacheable ) { 3258 3258 $new_request = str_replace( $fields, "{$wpdb->posts}.*", $this->request ); 3259 $cache_key = $this->generate_cache_key( $q , $new_request );3259 $cache_key = $this->generate_cache_key( $query_vars, $new_request ); 3260 3260 3261 3261 $cache_found = false; … … 3272 3272 $this->max_num_pages = $cached_results['max_num_pages']; 3273 3273 3274 if ( 'ids' === $q ['fields'] ) {3274 if ( 'ids' === $query_vars['fields'] ) { 3275 3275 $this->posts = $post_ids; 3276 3276 3277 3277 return $this->posts; 3278 } elseif ( 'id=>parent' === $q ['fields'] ) {3278 } elseif ( 'id=>parent' === $query_vars['fields'] ) { 3279 3279 _prime_post_parent_id_caches( $post_ids ); 3280 3280 … … 3297 3297 return $post_parents; 3298 3298 } else { 3299 _prime_post_caches( $post_ids, $q ['update_post_term_cache'], $q['update_post_meta_cache'] );3299 _prime_post_caches( $post_ids, $query_vars['update_post_term_cache'], $query_vars['update_post_meta_cache'] ); 3300 3300 /** @var WP_Post[] */ 3301 3301 $this->posts = array_map( 'get_post', $post_ids ); … … 3305 3305 } 3306 3306 3307 if ( 'ids' === $q ['fields'] ) {3307 if ( 'ids' === $query_vars['fields'] ) { 3308 3308 if ( null === $this->posts ) { 3309 3309 $this->posts = $wpdb->get_col( $this->request ); … … 3313 3313 $this->posts = array_map( 'intval', $this->posts ); 3314 3314 $this->post_count = count( $this->posts ); 3315 $this->set_found_posts( $q , $limits );3316 3317 if ( $q ['cache_results'] && $id_query_is_cacheable ) {3315 $this->set_found_posts( $query_vars, $limits ); 3316 3317 if ( $query_vars['cache_results'] && $id_query_is_cacheable ) { 3318 3318 $cache_value = array( 3319 3319 'posts' => $this->posts, … … 3328 3328 } 3329 3329 3330 if ( 'id=>parent' === $q ['fields'] ) {3330 if ( 'id=>parent' === $query_vars['fields'] ) { 3331 3331 if ( null === $this->posts ) { 3332 3332 $this->posts = $wpdb->get_results( $this->request ); … … 3334 3334 3335 3335 $this->post_count = count( $this->posts ); 3336 $this->set_found_posts( $q , $limits );3336 $this->set_found_posts( $query_vars, $limits ); 3337 3337 3338 3338 /** @var int[] */ … … 3353 3353 wp_cache_add_multiple( $post_parents_cache, 'posts' ); 3354 3354 3355 if ( $q ['cache_results'] && $id_query_is_cacheable ) {3355 if ( $query_vars['cache_results'] && $id_query_is_cacheable ) { 3356 3356 $cache_value = array( 3357 3357 'posts' => $post_ids, … … 3373 3373 && ( 3374 3374 wp_using_ext_object_cache() 3375 || ( ! empty( $limits ) && $q ['posts_per_page'] < 500 )3375 || ( ! empty( $limits ) && $query_vars['posts_per_page'] < 500 ) 3376 3376 ) 3377 3377 ); … … 3430 3430 if ( $post_ids ) { 3431 3431 $this->posts = $post_ids; 3432 $this->set_found_posts( $q , $limits );3433 _prime_post_caches( $post_ids, $q ['update_post_term_cache'], $q['update_post_meta_cache'] );3432 $this->set_found_posts( $query_vars, $limits ); 3433 _prime_post_caches( $post_ids, $query_vars['update_post_term_cache'], $query_vars['update_post_meta_cache'] ); 3434 3434 } else { 3435 3435 $this->posts = array(); … … 3437 3437 } else { 3438 3438 $this->posts = $wpdb->get_results( $this->request ); 3439 $this->set_found_posts( $q , $limits );3439 $this->set_found_posts( $query_vars, $limits ); 3440 3440 } 3441 3441 } … … 3449 3449 $unfiltered_posts = $this->posts; 3450 3450 3451 if ( $q ['cache_results'] && $id_query_is_cacheable && ! $cache_found ) {3451 if ( $query_vars['cache_results'] && $id_query_is_cacheable && ! $cache_found ) { 3452 3452 $post_ids = wp_list_pluck( $this->posts, 'ID' ); 3453 3453 … … 3461 3461 } 3462 3462 3463 if ( ! $q ['suppress_filters'] ) {3463 if ( ! $query_vars['suppress_filters'] ) { 3464 3464 /** 3465 3465 * Filters the raw post results array, prior to status checks. … … 3570 3570 // Put sticky posts at the top of the posts array. 3571 3571 $sticky_posts = get_option( 'sticky_posts' ); 3572 if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q ['ignore_sticky_posts'] ) {3572 if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $query_vars['ignore_sticky_posts'] ) { 3573 3573 $num_posts = count( $this->posts ); 3574 3574 $sticky_offset = 0; … … 3590 3590 3591 3591 // If any posts have been excluded specifically, Ignore those that are sticky. 3592 if ( ! empty( $sticky_posts ) && ! empty( $q ['post__not_in'] ) ) {3593 $sticky_posts = array_diff( $sticky_posts, $q ['post__not_in'] );3592 if ( ! empty( $sticky_posts ) && ! empty( $query_vars['post__not_in'] ) ) { 3593 $sticky_posts = array_diff( $sticky_posts, $query_vars['post__not_in'] ); 3594 3594 } 3595 3595 … … 3602 3602 'post_status' => 'publish', 3603 3603 'posts_per_page' => count( $sticky_posts ), 3604 'suppress_filters' => $q ['suppress_filters'],3605 'cache_results' => $q ['cache_results'],3606 'update_post_meta_cache' => $q ['update_post_meta_cache'],3607 'update_post_term_cache' => $q ['update_post_term_cache'],3608 'lazy_load_term_meta' => $q ['lazy_load_term_meta'],3604 'suppress_filters' => $query_vars['suppress_filters'], 3605 'cache_results' => $query_vars['cache_results'], 3606 'update_post_meta_cache' => $query_vars['update_post_meta_cache'], 3607 'update_post_term_cache' => $query_vars['update_post_term_cache'], 3608 'lazy_load_term_meta' => $query_vars['lazy_load_term_meta'], 3609 3609 ) 3610 3610 ); … … 3617 3617 } 3618 3618 3619 if ( ! $q ['suppress_filters'] ) {3619 if ( ! $query_vars['suppress_filters'] ) { 3620 3620 /** 3621 3621 * Filters the array of retrieved posts after they've been fetched and … … 3640 3640 $this->posts = array_map( 'get_post', $this->posts ); 3641 3641 3642 if ( $q ['cache_results'] ) {3642 if ( $query_vars['cache_results'] ) { 3643 3643 if ( $is_unfiltered_query && $unfiltered_posts === $this->posts ) { 3644 update_post_caches( $this->posts, $post_type, $q ['update_post_term_cache'], $q['update_post_meta_cache'] );3644 update_post_caches( $this->posts, $post_type, $query_vars['update_post_term_cache'], $query_vars['update_post_meta_cache'] ); 3645 3645 } else { 3646 3646 $post_ids = wp_list_pluck( $this->posts, 'ID' ); 3647 _prime_post_caches( $post_ids, $q ['update_post_term_cache'], $q['update_post_meta_cache'] );3647 _prime_post_caches( $post_ids, $query_vars['update_post_term_cache'], $query_vars['update_post_meta_cache'] ); 3648 3648 } 3649 3649 } … … 3656 3656 } 3657 3657 3658 if ( ! empty( $this->posts ) && $q ['update_menu_item_cache'] ) {3658 if ( ! empty( $this->posts ) && $query_vars['update_menu_item_cache'] ) { 3659 3659 update_menu_item_cache( $this->posts ); 3660 3660 } 3661 3661 3662 if ( $q ['lazy_load_term_meta'] ) {3662 if ( $query_vars['lazy_load_term_meta'] ) { 3663 3663 wp_queue_posts_for_term_meta_lazyload( $this->posts ); 3664 3664 } … … 3675 3675 * @global wpdb $wpdb WordPress database abstraction object. 3676 3676 * 3677 * @param array $q Query variables.3678 * @param string $limits LIMIT clauses of the query.3679 */ 3680 private function set_found_posts( $q , $limits ) {3677 * @param array $query_vars Query variables. 3678 * @param string $limits LIMIT clauses of the query. 3679 */ 3680 private function set_found_posts( $query_vars, $limits ) { 3681 3681 global $wpdb; 3682 3682 … … 3685 3685 * null, or false to accommodate caching plugins that fill posts later. 3686 3686 */ 3687 if ( $q ['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) {3687 if ( $query_vars['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) { 3688 3688 return; 3689 3689 } … … 3724 3724 3725 3725 if ( ! empty( $limits ) ) { 3726 $this->max_num_pages = (int) ceil( $this->found_posts / $q ['posts_per_page'] );3726 $this->max_num_pages = (int) ceil( $this->found_posts / $query_vars['posts_per_page'] ); 3727 3727 } 3728 3728 } … … 4444 4444 } 4445 4445 4446 $q v= $this->get( 'feed' );4447 if ( 'feed' === $q v) {4448 $q v= get_default_feed();4449 } 4450 4451 return in_array( $q v, (array) $feeds, true );4446 $query_var = $this->get( 'feed' ); 4447 if ( 'feed' === $query_var ) { 4448 $query_var = get_default_feed(); 4449 } 4450 4451 return in_array( $query_var, (array) $feeds, true ); 4452 4452 } 4453 4453
Note: See TracChangeset
for help on using the changeset viewer.