I have WordPress installed and I have this form on each category page sidebar:
<form name="tags" onChange="document.forms.tags.submit();">
<input type="checkbox" name="tag" value="tag1" <?php if((isset($_GET["tag"])) && $_GET["tag"] == "tag1") { echo "checked";}?>>tag1<br>
<input type="checkbox" name="tag" value="tag2" <?php if((isset($_GET["tag"])) && $_GET["tag"] == "tag2") { echo "checked";}?>>tag2
</form>
The goal is to create an url like /?tag=tag1+tag2 and so on.
With the above code I get the url like this: /?tag=tag1&tag=tag2.
I’ve searched for two weeks and tried a lot, but nothing works for me. I’ve tried for example
<input type="checkbox" name="tag[]" value="tag1" <?php if((isset($_GET["tag"])) && $_GET["tag"] == "tag1") { echo "checked";}?>>tag1
but then i get ?tag%5B%5D=tag1
and WordPress don’t find any results.
The form submit each time a checkbox is checked.
If I use radio input fields, then it works great, because then there’s one value each time, but I want to pass multiple values with the same name and render a url like /?tag=tag1+tag2+tag3+tag4 etc.
Can anybody help me with this problem, because I don’t know how to get this work for me. Thanks!
this is what you want:
take a look on add_query_arg() and get_query_var()
Consider on this example http://codepad.org/s08Jmseg