admin管理员组文章数量:1130349
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.
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.
本文标签: excludeDo not allow to search certain words
版权声明:本文标题:exclude - Do not allow to search certain words 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749078807a2312723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论