Changeset 7491 for trunk/wp-includes/query.php
- Timestamp:
- 03/23/2008 05:02:11 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/query.php
r7109 r7491 115 115 116 116 if ( in_array( $tag_obj->slug, $slug ) ) 117 return true; 118 119 return false; 120 } 121 122 function is_tax( $slug = '' ) { 123 global $wp_query; 124 125 if ( !$wp_query->is_tax ) 126 return false; 127 128 if ( empty($slug) ) 129 return true; 130 131 $term = $wp_query->get_queried_object(); 132 133 $slug = (array) $slug; 134 135 if ( in_array( $term->slug, $slug ) ) 117 136 return true; 118 137 … … 371 390 var $is_category = false; 372 391 var $is_tag = false; 392 var $is_tax = false; 373 393 var $is_search = false; 374 394 var $is_feed = false; … … 396 416 $this->is_category = false; 397 417 $this->is_tag = false; 418 $this->is_tax = false; 398 419 $this->is_search = false; 399 420 $this->is_feed = false; … … 658 679 } 659 680 681 if ( empty($qv['taxonomy']) || empty($qv['term']) ) { 682 $this->is_tax = false; 683 } else { 684 $this->is_tax = true; 685 } 686 660 687 if ( empty($qv['author']) || ($qv['author'] == '0') ) { 661 688 $this->is_author = false; … … 841 868 if ( $q['m'] ) { 842 869 $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); 843 $where .= ' AND YEAR(post_date)='. substr($q['m'], 0, 4);870 $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4); 844 871 if (strlen($q['m'])>5) 845 $where .= ' AND MONTH(post_date)='. substr($q['m'], 4, 2);872 $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2); 846 873 if (strlen($q['m'])>7) 847 $where .= ' AND DAYOFMONTH(post_date)='. substr($q['m'], 6, 2);874 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2); 848 875 if (strlen($q['m'])>9) 849 $where .= ' AND HOUR(post_date)='. substr($q['m'], 8, 2);876 $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2); 850 877 if (strlen($q['m'])>11) 851 $where .= ' AND MINUTE(post_date)='. substr($q['m'], 10, 2);878 $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2); 852 879 if (strlen($q['m'])>13) 853 $where .= ' AND SECOND(post_date)='. substr($q['m'], 12, 2);880 $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2); 854 881 } 855 882 856 883 if ( '' !== $q['hour'] ) 857 $where .= " AND HOUR( post_date)='" . $q['hour'] . "'";884 $where .= " AND HOUR($wpdb->posts.post_date)='" . $q['hour'] . "'"; 858 885 859 886 if ( '' !== $q['minute'] ) 860 $where .= " AND MINUTE( post_date)='" . $q['minute'] . "'";887 $where .= " AND MINUTE($wpdb->posts.post_date)='" . $q['minute'] . "'"; 861 888 862 889 if ( '' !== $q['second'] ) 863 $where .= " AND SECOND( post_date)='" . $q['second'] . "'";890 $where .= " AND SECOND($wpdb->posts.post_date)='" . $q['second'] . "'"; 864 891 865 892 if ( $q['year'] ) 866 $where .= " AND YEAR( post_date)='" . $q['year'] . "'";893 $where .= " AND YEAR($wpdb->posts.post_date)='" . $q['year'] . "'"; 867 894 868 895 if ( $q['monthnum'] ) 869 $where .= " AND MONTH( post_date)='" . $q['monthnum'] . "'";896 $where .= " AND MONTH($wpdb->posts.post_date)='" . $q['monthnum'] . "'"; 870 897 871 898 if ( $q['day'] ) 872 $where .= " AND DAYOFMONTH( post_date)='" . $q['day'] . "'";899 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)='" . $q['day'] . "'"; 873 900 874 901 if ('' != $q['name']) { 875 902 $q['name'] = sanitize_title($q['name']); 876 $where .= " AND post_name = '" . $q['name'] . "'";903 $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'"; 877 904 } else if ('' != $q['pagename']) { 878 905 if ( isset($this->queried_object_id) ) … … 904 931 $q['attachment'] = sanitize_title(basename($attach_paths)); 905 932 $q['name'] = $q['attachment']; 906 $where .= " AND post_name = '" . $q['attachment'] . "'";933 $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'"; 907 934 } 908 935 909 936 if ( $q['w'] ) 910 $where .= " AND WEEK( post_date, 1)='" . $q['w'] . "'";937 $where .= " AND WEEK($wpdb->posts.post_date, 1)='" . $q['w'] . "'"; 911 938 912 939 if ( intval($q['comments_popup']) ) … … 942 969 foreach((array)$q['search_terms'] as $term) { 943 970 $term = addslashes_gpc($term); 944 $search .= "{$searchand}(( post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}'))";971 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))"; 945 972 $searchand = ' AND '; 946 973 } 947 974 $term = $wpdb->escape($q['s']); 948 975 if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] ) 949 $search .= " OR ( post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')";976 $search .= " OR ($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}')"; 950 977 951 978 if ( !empty($search) ) … … 1113 1140 } 1114 1141 1142 // Taxonomies 1143 if ( $this->is_tax ) { 1144 $terms = get_terms($q['taxonomy'], array('slug'=>$q['term'])); 1145 foreach ( $terms as $term ) 1146 $term_ids[] = $term->term_id; 1147 $post_ids = get_objects_in_term($term_ids, $q['taxonomy']); 1148 1149 if ( count($post_ids) ) { 1150 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; 1151 $post_type = 'any'; 1152 $q['post_status'] = 'publish'; 1153 $post_status_join = true; 1154 } else { 1155 $whichcat = " AND 0 = 1"; 1156 } 1157 } 1158 1115 1159 // Author/user stuff 1116 1160 … … 1130 1174 } 1131 1175 $author_array = preg_split('/[,\s]+/', $q['author']); 1132 $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);1176 $whichauthor .= " AND ($wpdb->posts.post_author ".$eq.' '.intval($author_array[0]); 1133 1177 for ($i = 1; $i < (count($author_array)); $i = $i + 1) { 1134 $whichauthor .= ' '.$andor. ' post_author '.$eq.' '.intval($author_array[$i]);1178 $whichauthor .= ' '.$andor." $wpdb->posts.post_author ".$eq.' '.intval($author_array[$i]); 1135 1179 } 1136 1180 $whichauthor .= ')'; … … 1150 1194 $q['author_name'] = sanitize_title($q['author_name']); 1151 1195 $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'"); 1152 $whichauthor .= ' AND (post_author = '.intval($q['author']).')';1196 $whichauthor .= " AND ($wpdb->posts.post_author = ".intval($q['author']).')'; 1153 1197 } 1154 1198 … … 1165 1209 // Order by 1166 1210 if ( empty($q['orderby']) ) { 1167 $q['orderby'] = 'post_date '.$q['order'];1211 $q['orderby'] = "$wpdb->posts.post_date ".$q['order']; 1168 1212 } else { 1169 1213 // Used to filter values … … 1181 1225 case 'menu_order': 1182 1226 case 'ID': 1227 $orderby = "$wpdb->posts.ID"; 1183 1228 break; 1184 1229 case 'rand': … … 1186 1231 break; 1187 1232 default: 1188 $orderby = 'post_'. $orderby;1233 $orderby = "$wpdb->posts.post_" . $orderby; 1189 1234 } 1190 1235 if ( in_array($orderby_array[$i], $allowed_keys) ) … … 1196 1241 1197 1242 if ( empty($q['orderby']) ) 1198 $q['orderby'] = 'post_date '.$q['order'];1243 $q['orderby'] = "$wpdb->posts.post_date ".$q['order']; 1199 1244 } 1200 1245 1201 1246 if ( $this->is_attachment ) { 1202 $where .= " AND post_type = 'attachment'";1247 $where .= " AND $wpdb->posts.post_type = 'attachment'"; 1203 1248 } elseif ($this->is_page) { 1204 $where .= " AND post_type = 'page'";1249 $where .= " AND $wpdb->posts.post_type = 'page'"; 1205 1250 } elseif ($this->is_single) { 1206 $where .= " AND post_type = 'post'";1251 $where .= " AND $wpdb->posts.post_type = 'post'"; 1207 1252 } elseif ( 'any' == $post_type ) { 1208 1253 $where .= ''; 1209 1254 } else { 1210 $where .= " AND post_type = '$post_type'";1255 $where .= " AND $wpdb->posts.post_type = '$post_type'"; 1211 1256 } 1212 1257 1213 1258 if ( isset($q['post_status']) && '' != $q['post_status'] ) { 1259 $statuswheres = array(); 1214 1260 $q_status = explode(',', $q['post_status']); 1215 1261 $r_status = array(); 1216 1262 $p_status = array(); 1217 1263 if ( in_array( 'draft' , $q_status ) ) 1218 $r_status[] = " post_status = 'draft'";1264 $r_status[] = "$wpdb->posts.post_status = 'draft'"; 1219 1265 if ( in_array( 'pending', $q_status ) ) 1220 $r_status[] = " post_status = 'pending'";1266 $r_status[] = "$wpdb->posts.post_status = 'pending'"; 1221 1267 if ( in_array( 'future' , $q_status ) ) 1222 $r_status[] = " post_status = 'future'";1268 $r_status[] = "$wpdb->posts.post_status = 'future'"; 1223 1269 if ( in_array( 'inherit' , $q_status ) ) 1224 $r_status[] = " post_status = 'inherit'";1270 $r_status[] = "$wpdb->posts.post_status = 'inherit'"; 1225 1271 if ( in_array( 'private', $q_status ) ) 1226 $p_status[] = " post_status = 'private'";1272 $p_status[] = "$wpdb->posts.post_status = 'private'"; 1227 1273 if ( in_array( 'publish', $q_status ) ) 1228 $r_status[] = " post_status = 'publish'";1274 $r_status[] = "$wpdb->posts.post_status = 'publish'"; 1229 1275 1230 1276 if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) { … … 1235 1281 if ( !empty($r_status) ) { 1236 1282 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can("edit_others_{$post_type}s") ) 1237 $ where .= " AND (post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";1283 $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))"; 1238 1284 else 1239 $ where .= " AND(" . join( ' OR ', $r_status ) . ")";1285 $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; 1240 1286 } 1241 1287 if ( !empty($p_status) ) { 1242 1288 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can("read_private_{$post_type}s") ) 1243 $ where .= " AND (post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";1289 $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))"; 1244 1290 else 1245 $where .= " AND (" . join( ' OR ', $p_status ) . ")"; 1246 } 1291 $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; 1292 } 1293 if ( $post_status_join ) { 1294 $join .= " INNER JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) "; 1295 foreach ( $statuswheres as $index => $statuswhere ) 1296 $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; 1297 } 1298 foreach ( $statuswheres as $statuswhere ) 1299 $where .= " AND $statuswhere"; 1247 1300 } elseif ( !$this->is_singular ) { 1248 $where .= " AND ( post_status = 'publish'";1301 $where .= " AND ($wpdb->posts.post_status = 'publish'"; 1249 1302 1250 1303 if ( is_admin() ) 1251 $where .= " OR post_status = 'future' OR post_status = 'draft' ORpost_status = 'pending'";1304 $where .= " OR $wpdb->posts.post_status = 'future' OR $wpdb->posts.post_status = 'draft' OR $wpdb->posts.post_status = 'pending'"; 1252 1305 1253 1306 if ( is_user_logged_in() ) { 1254 $where .= current_user_can( "read_private_{$post_type}s" ) ? " OR post_status = 'private'" : " OR post_author = $user_ID ANDpost_status = 'private'";1307 $where .= current_user_can( "read_private_{$post_type}s" ) ? " OR $wpdb->posts.post_status = 'private'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = 'private'"; 1255 1308 } 1256 1309 … … 1505 1558 $this->queried_object = &$tag; 1506 1559 $this->queried_object_id = (int) $tag_id; 1560 } else if ($this->is_tax) { 1561 $tax = $this->get('taxonomy'); 1562 $slug = $this->get('term'); 1563 $term = &get_terms($tax, array('slug'=>$slug)); 1564 if ( is_wp_error($term) ) 1565 return $term; 1566 $this->queried_object = $term; 1567 $this->queried_object_id = $term->term_id; 1507 1568 } else if ($this->is_posts_page) { 1508 1569 $this->queried_object = & get_page(get_option('page_for_posts'));
Note: See TracChangeset
for help on using the changeset viewer.