Исключить категории из результатов поиска WordPress

Excluding a category (or categories) from the WordPress search results is easy peezy, however, that doesn’t stop most of the snippets I’ve found from doing it wrong.

<?php
add_filter( 'pre_get_posts', 'ja_search_filter' );
/**
 * Exclude category 7 from search results.
 *
 * @since ?.?.?
 * @author Jared Atchison
 * @link https://gist.github.com/1300302
 *
 * @param WP_Query $query Existing query object
 * @return WP_Query Amended query object
 */
function ja_search_filter( $query ) {
	if ( $query->is_search && !is_admin() )
		$query->set( 'cat','-7' );
	return $query;
}

для исключения нескольких категорий прописываем так:

$query->set( ‘cat’, ‘-1,-1347’ );

источник