How to exclude categories from recent posts, recent comments & category widgets?

The original author isn’t quite right in saying “which is merely the more elegant way to write”.

set_query_var() will always override the main query, whereas if you actually use:

$wp_query->set( 'category__not_in', $excluded );

… it will work for any instance of query_posts(), such as the recent posts widget.

Leave a Comment