• Hello,

    For the past few hours I have been searching/ trying to think of how to get WordPress’s search parameter, ‘s’, to show results if ANY of the keywords match. Not only if they all do.

    Short of custom SQL, is there any way to do this with the WP_Query?

    I was thinking of exploding the searched phrase then looping through the search for each word, then merging the arrays. But all the code I tried writing ended up broken.

    Any help is GREAAAATLY appreciated.

    Thanks!
    Andrew

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Andrew Rockwell

    (@rockwell15)

    I actually gave that a try and it didn’t work. Even after removing query_posts() from my page :/

    I’m not going to tell you what to do, but in my experience, it’s better to try to use an existing solution to problems such as these. Consider the following search term: “pancakes and syrup”.

    explode( ' ', $_GET['s'];

    would give you an array(“pancakes”, “and”, “syrup”) and searching for “and” would return basically everything.

    Search plugins typically include filters for partial match, etc. It’s probably better use of your time to configure a search plugin to work rather than code your own solution. This isn’t the case for all issues, but in the particular case, it probably is.

    Hope that helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP_Query Search Parameter for ANY words’ is closed to new replies.