The search plugin I’m using in WordPress, (Relavenssi), allows the user to add quotes to search terms in order to search for phrases, for example “search phrase”.
How would I code it so that when the user selects a radio/check box called ‘Exact Match’, the quotes are automatically added to the search query rather than being added into the search box by the user?
Any help greatly appreciated, S.
Search form code below:
<form action="<?php bloginfo('home'); ?>/" method="post">
<div class="search-icon">
<label for="search" accesskey="4" class="hidden">Search the site</label>
<input type="text" name="s" id="search" value="Enter search term" onblur="this.value = this.value || this.defaultValue;" onfocus="this.value = '';" />
<input type="submit" name="submit" value="GO" class="s-btn" />
<p><a href="#" id="search-anchor">Search Options</a></p>
<div class="option-slide">
<input type="radio" name="sentence" value="" checked="checked" /><label>All Words</label><br />
<input type="radio" name="sentence" value="???" /><label>Exact Match</label>
</div>
</div>
</form>
Edit: Based on the answer from @Tristar Web Design below, I have now added this php code below my search form, although it doesn’t work properly. It echoes out ok but isn’t passing the query back. How do I pass/send the updated search query back to WordPress?
if(isset($_POST['s']) && $_POST['sentence'] == 'exact') {
$_POST['s'] = '"'.get_search_query().'"';
echo $_POST['s'];
} else {
echo "2";
}
A couple of methods for this I guess.
Edit:
Maybe consider this jQuery method (This method assumes that jQuery has been loaded, and I also added my own noConflict() variable) –