1

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?

1 Answer 1

1

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):

?s=search&filtersearch=1&province=Example&searchvalue=Another-Example

To get the value of province, you'd use this in your PHP:

$province = $_GET['province']

You should then be able to use that in a function to filter your search.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. Am creating a form so I can't use a permalink, am getting the province value from a dropdown on the form. The issue is that Wordpress automatically strips out variable it doesn't recognise before building the page therefore ` ?s=search&filtersearch=1&province=Example&searchvalue=Another-Example` ends up as ?s=search Your supposed to add the new variable either in a plugin or in the function file (see filter_add_query_vars above) but that wasn't working for me. I ended up having to add the variables directly onto the wordpress query string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.