Changeset 3767
- Timestamp:
- 05/08/2006 02:16:24 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/query.php
r3697 r3767 500 500 501 501 // First let's clear some variables 502 $distinct = ''; 502 503 $whichcat = ''; 503 504 $whichauthor = ''; … … 693 694 $q['cat'] = ''.urldecode($q['cat']).''; 694 695 $q['cat'] = addslashes_gpc($q['cat']); 695 if (stristr($q['cat'],'-')) {696 // Note: if we have a negative, we ignore all the positives. It must697 // always mean 'everything /except/ this one'. We should be able to do698 // multiple negatives but we don't :-(699 $eq = '!=';700 $andor = 'AND';701 $q['cat'] = explode('-',$q['cat']);702 $q['cat'] = intval($q['cat'][1]);703 } else {704 $eq = '=';705 $andor = 'OR';706 }707 696 $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) "; 708 697 $cat_array = preg_split('/[,\s]+/', $q['cat']); 709 $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]); 710 $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' '); 711 for ($i = 1; $i < (count($cat_array)); $i = $i + 1) { 712 $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]); 713 $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' '); 714 } 715 $whichcat .= ')'; 716 if ($eq == '!=') { 717 $q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category. 718 } 698 $in_cats = $out_cats = ''; 699 foreach ( $cat_array as $cat ) { 700 $in = strstr($cat, '-') ? false : true; 701 $cat = trim($cat, '-'); 702 if ( $in ) 703 $in_cats .= "$cat, " . get_category_children($cat, '', ', '); 704 else 705 $out_cats .= "$cat, " . get_category_children($cat, '', ', '); 706 } 707 $in_cats = substr($in_cats, 0, -2); 708 $out_cats = substr($out_cats, 0, -2); 709 if ( strlen($in_cats) > 0 ) 710 $in_cats = " AND category_id IN ($in_cats)"; 711 if ( strlen($out_cats) > 0 ) 712 $out_cats = " AND category_id NOT IN ($out_cats)"; 713 $whichcat = $in_cats . $out_cats; 714 $distinct = 'DISTINCT'; 719 715 } 720 716 … … 747 743 $tables = ", $wpdb->post2cat, $wpdb->categories"; 748 744 $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) "; 749 $whichcat = " AND (category_id = '" . $q['cat'] . "'"; 750 $whichcat .= get_category_children($q['cat'], " OR category_id = "); 745 $whichcat = " AND category_id IN ({$q['cat']}, "; 746 $whichcat .= get_category_children($q['cat'], '', ', '); 747 $whichcat = substr($whichcat, 0, -2); 751 748 $whichcat .= ")"; 749 $distinct = 'DISTINCT'; 752 750 } 753 751 … … 878 876 $groupby = 'GROUP BY ' . $groupby; 879 877 $join = apply_filters('posts_join_paged', $join); 880 $orderby = apply_filters('posts_orderby', $q['orderby']); 881 $request = " SELECT * FROM $wpdb->posts $join WHERE 1=1 $where $groupby ORDER BY $orderby $limits"; 878 $orderby = apply_filters('posts_orderby', $q['orderby']); 879 $distinct = apply_filters('posts_distinct', $distinct); 880 $fields = apply_filters('posts_fields', "$wpdb->posts.*"); 881 $request = " SELECT $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby ORDER BY $orderby $limits"; 882 882 $this->request = apply_filters('posts_request', $request); 883 883
Note: See TracChangeset
for help on using the changeset viewer.