Reputation: 138
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
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