• I need to use exact search but also need the search to work if their is a space in the word.
    Example:
    Post Title AD1000
    The search should find the title if the user searches by “AD1000 or AD 1000”

    Any idea how my exact function should be written:

    // Exact Search Function
    
    add_action('pre_get_posts', 'my_make_search_exact', 10);
    function my_make_search_exact($query){
    
        if(!is_admin() && $query->is_main_query() && $query->is_search) :
            $query->set('exact', true);
        endif;
    
    }
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    How would code know where a space is allowed? Only between alpha and numeric?

    Generally speaking, you would need to convert the SQL LIKE operators to RLIKE and convert the search term to a proper regexp. The “posts_request” filter can be used for this.

Viewing 1 replies (of 1 total)
  • The topic ‘Exact search but also include space in word’ is closed to new replies.