I would like to delete (not allow) searches with certain keywords (eg "of", "a").
If the search is done using exactly these terms, do not return anything or redirect to 404 page ...
Thanks guys.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI would like to delete (not allow) searches with certain keywords (eg "of", "a").
If the search is done using exactly these terms, do not return anything or redirect to 404 page ...
Thanks guys.
Try this in your functions.php
, and change news
for whatever you want to be blocked in your site.
add_action('wp', 'check_search');
function check_search() {
global $wp_query;
if (!$s = get_search_query())
return false;
if (preg_match('/news/', $s)) {
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
}
Hope it helps.
global $wp_query
line. With that you should have your functionality running.
– vmassuchetto
Jun 23 '12 at 14:26
global $wp_query
was missing. Thank again.
– BobGCA
Jun 24 '12 at 5:02