$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>exclude - Do not allow to search certain words|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

exclude - Do not allow to search certain words

matteradmin10PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 3

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far