For example, if I search the site with the following parameters. http://localhost/?s=KEYWORD&tag[]=TAG1&tag[]=TAG2

This is like saying that Posts where [keyword is 'KEYWORD'] OR [has 'TAG1' tag] OR [has 'TAG2' tag].

So this is an "OR search", I don't want that, I want "AND search". How can I change this default behavior??

  • Ajax search lite is the best search plugin for WP. It supports your required functionality. Replacing the default WordPress search requires you to write a plugin yourself - and don't modify the core. See this page from the codex: codex.wordpress.org/Creating_a_Search_Page Jul 12 '17 at 9:08

The default is "AND search" but not "OR search".

We can see that here in the WP_Query::parse_search() method:

if ( ! empty( $search ) ) {
    $search = " AND ({$search}) ";

Here I've posted a hack, some time ago, to get the OR version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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