admin管理员组文章数量:1124393
Is it possible to search only by post_tags? If the tag is not found, no result is displayed.
Any modifications to functions.php or premium plugin?
I tried using WordPress Extended Search, but it always returns title and content results.
Is it possible to search only by post_tags? If the tag is not found, no result is displayed.
Any modifications to functions.php or premium plugin?
I tried using WordPress Extended Search, but it always returns title and content results.
Share Improve this question asked Mar 5, 2024 at 13:04 AddeAdde 1 1- Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Mar 6, 2024 at 15:48
1 Answer
Reset to default 0search behaviour in wp to only search by post tags and not return results for titles or content if the tag is not found.
You can achieve this by customizing the search query using functions.php
function custom_search_filter($query) {
// Check if it's the main query and it's a search query
if ($query->is_main_query() && $query->is_search()) {
// Get the search query
$search_query = get_search_query();
// Modify the query to only search for post tags
$query->set('tag', $search_query);
}
}
add_action('pre_get_posts', 'custom_search_filter');
本文标签: tagsSearch only by posttags
版权声明:本文标题:tags - Search only by post_tags 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736628729a1945731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论