[wp-hackers] Best Way of Excluding Categories from wp_list_categories

Aaron Harun admin at anthologyoi.com
Tue Mar 11 04:32:03 GMT 2008


In one of my old plugins I had to do this. You have to hook into the
get_terms hook. I used the following code. (The code was from 2.1 and
I updated it to 2.3 from memory so it may not be perfect.)

add_filter('get_categories', 'filter_categories');

function filter_categories ($input_categories,$type)
global  $good_cats;

	if($type == 'category'){
		return $input_categories;
	}

	$filtered_results = array();
	foreach($input_categories as $result){
		if(in_array($result->term_id,$good_cats,true) && $result->term_id !='' ){
			array_push($filtered_results, $result);
		}
	}

	return $filtered_results;
}

$good_cats is an array of category ids that you DO want. You can
reverse the check to check for something not in the array.


On 3/11/08, Matt <speedboxer at gmail.com> wrote:
> I'm wondering what the best way (or anyway, really) of excluding categories
>  (by ID) from wp_list_categories (from a plugin).
>
>  It's probably something simple I'm missing. :P
>
>  Thanks,
>
>
>  --
>  Matt (speedboxer at gmail.com)
>  http://mattsblog.ca/
>  _______________________________________________
>  wp-hackers mailing list
>  wp-hackers at lists.automattic.com
>  http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list