[wp-hackers] Coding Projects

Brian Dupuis wordpress at coldforged.org
Wed Jan 19 18:02:56 GMT 2005


Yeah, I dealt with this personally on my site (http://coldforged.org) 
because I have two exclusions: my "asides" and my "currently reading". 
So, in my index I have cat="-27 -28" as those are the categories I want 
excluded. The way I looked at it -- as Adi hinted -- you're either going 
to want to include categories or exclude categories. Therefore, I look 
for an exclusion and assume they're all excluded. Then, I change the 
boolean operators appropriately and simply call an abs() on the intval 
of the categories later. Ahh hell, let me just paste.

$q['cat'] = ''.urldecode($q['cat']).'';
$q['cat'] = addslashes_gpc($q['cat']);
if (stristr($q['cat'],'-')) {
        $eq = '!=';
        $andor = 'AND';
} else {
        $eq = '=';
        $andor = 'OR';
}
$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = 
$wpdb->post2cat.post_id) ";
$cat_array = explode(' ',$q['cat']);
$whichcat .= ' AND (category_id '.$eq.' '.abs(intval($cat_array[0]));
$whichcat .= get_category_children($cat_array[0], ' '.$andor.' 
category_id '.$eq.' ');
for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
        $whichcat .= ' '.$andor.' category_id '.$eq.' 
'.abs(intval($cat_array[$i]));
        $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' 
category_id '.$eq.' ');
}
$whichcat .= ')';

I don't know whether it works in the "general case", but I've been using 
it on my blog for quite a while to no ill effect.


Adi Jörg Sieker wrote:

> Hi,
>
> Ryan Boren wrote:
>
>> Support mutltiple negatives for category queries.  See get_posts() in
>> classes.php where we process 'cat'.  Look for the comment lamenting the
>> fact that we don't support this.
>
>
> I'm just having ago at this and now I'm a little puzzled.
> Currently if any category is specified as negative it'll
> discard all others.
> Now we would like multiple negatives which is no problem.
>
> But what is the expected outcome of positives and negatives in one
> query? For example this: query_posts('cat=3 -1 -4 2');
>
>
> Regards
>    Adi
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers
>
>
>


More information about the hackers mailing list