Am customizing a search form in WordPress and I can’t seem to be able to add other parameters to the form. Below is my form
<form id="searchform" action="/">
<div class="row">
<input type="input" name="searchvalue" class="searchinput" placeholder="Search..">
</div>
<div class="row">
<label>Province</label>
<select name="province" id="province" class="filterpostsbyprovince">
<option value="0" selected="selected">Select Province</option>
</select>
</div>
<div class="row">
<input type="submit" value="SEARCH" style="cursor: pointer">
</div>
<input type="hidden" name="filtersearch" value="1">
<input type="hidden" name="s" value="search">
</form>
Based on the above form my search query should be something like ?s=search&filtersearch=1&province=""&searchvalue=""
however WordPress passes on s=search to the search results page. I’ve added filtersearch on my functions file but this doesn’t seem to help
function filter_add_query_vars($query_vars) {
$query_vars[] = 'filtersearch';
return $query_vars;
}
add_filter( 'query_vars', 'filter_add_query_vars' );
I have tried removing permalinks but this doesn’t help. Can anybody help me out?
Not an exact answer, but you might want to look into using $_GET variables given how you’re structuring this.
You’d want your permalink to look like this (notice the quotes are removed):
To get the value of province, you’d use this in your PHP:
You should then be able to use that in a function to filter your search.