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.
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.
Share Improve this question edited Jun 23, 2012 at 10:49 BobGCA2 asked Jun 23, 2012 at 10:25 BobGCA2BobGCA2 3171 gold badge6 silver badges17 bronze badges 5- I know this isn't helpful, but can I ask why you want to do that? – Dominic Commented Jun 23, 2012 at 11:09
- 1 Sure @Dominic. Some spammers tend to enter short terms as "a" or "of". On a site with many inputs and hosting "very" shared, it takes time to return results or gives error. – BobGCA2 Commented Jun 23, 2012 at 11:22
- 2 possible duplicate of Set minimum number of characters in the search – Michael Commented Jun 23, 2012 at 11:27
- @Michael Stop words and word length are different topics. – fuxia ♦ Commented Jun 23, 2012 at 15:31
- @toscho Sure, however the central problem is how to influence the search to deal with these words, which brings it (in my personal opinion) basically back to one topic. – Michael Commented Jun 23, 2012 at 16:59
1 Answer
Reset to default 3Try 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.