Dan W
Dan W

Reputation: 138

if search query is met function

I want to create a function for wordpress that display a particular banner only if certain search terms stored in array are entered into the search box.

So for example if i entered the string "yellow" I would get a banner and search results for that string because it is in the array

But if i entered the string "orange" I would only get search terms

not too sure where to start with this so any help would be much appreciated

Cheers

Daniel Wakefield Web Designer Cheshire

Upvotes: 1

Views: 483

Answers (1)

Joe Buckle
Joe Buckle

Reputation: 871

To check if a word exists within a search term, add each searched word into an array using explode(). Then use in_array() to see if that word exists.

$words_array = explode(' ', $_GET['s']);
if(in_array('orange', $words_array)) {
    // search contains orange
} else { 
    // search does not contain orange
} 

Upvotes: 3

Related Questions