function exclude_category_from_search($query) { if ($query->is_search) { $cat_id = get_cat_ID('politics'); $query->set('cat', '-'.$cat_id); } return $query; } add_filter('pre_get_posts','exclude_category_from_search');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter