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.

  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Mar 6 at 15:48

1 Answer 1


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');
  • Inserting the code at the end of function.php had no effect. It brings results from the post content
    – Adde
    Mar 5 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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