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 know this isn't helpful, but can I ask why you want to do that? – Dominic Jun 23 '12 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. – BobGCA Jun 23 '12 at 11:22
  • 2
    possible duplicate of Set minimum number of characters in the search – Michael Jun 23 '12 at 11:27
  • @Michael Stop words and word length are different topics. – fuxia Jun 23 '12 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 Jun 23 '12 at 16:59

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)) {


Hope it helps.

  • Hi @Vinicius Massuchetto ...('/news/', $s)) unfortunately it did not work. site.com/?s=news usually is returning results. – BobGCA Jun 23 '12 at 13:19
  • I'm sorry. Try again with the new snippet. =D – vmassuchetto Jun 23 '12 at 13:51
  • What a pity @Vinicius Massuchetto - Oops! Fatal error: Call to a member function set_404()... What should be happening? – BobGCA Jun 23 '12 at 14:17
  • I can't believe! While pasting the new snippet I forgot the global $wp_query line. With that you should have your functionality running. – vmassuchetto Jun 23 '12 at 14:26
  • Oh, yes @Massuchetto Vinicius, global $wp_query was missing. Thank again. – BobGCA Jun 24 '12 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.