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

1 Answer 1

Reset to default 0

search 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