0

I'm trying to have two separate search fields for tags on a search page on my Wordpress site, but it seems have a duplicate instance of a taxonomy breaks the search functionality.

<form method="get" id="search form" action="/">
<div>
<input type="text" value="" name="tag" id="tag" />
<input type="text" value="" name="tag" id="tag" />
<input type="hidden" value="94" name="cat" id="scat" />
<input type="submit" id="search_submit" name="Search" value="Search"/>
</div>
</form>

Is there any way for me to have the second tag field in this search?

5
  • why not use a select or checkbox field instead? Both will allow you to choose multiple tags.
    – ngearing
    Jun 1, 2015 at 3:54
  • They will end up being first name and last name fields, each will have a different set of suggestions.
    – jpd527
    Jun 1, 2015 at 4:13
  • So name="first_name" and name="last_name"?
    – s_ha_dum
    Jun 1, 2015 at 4:15
  • I tried that, the name determines which taxonomy it searches, but I want that taxonomy to be tag.
    – jpd527
    Jun 1, 2015 at 4:28
  • So rewrite your form handler. I don't understand what the problem is.
    – s_ha_dum
    Jun 1, 2015 at 5:29

1 Answer 1

1

jpd527,

Please remember that 'tag' is singular and not plural. Here your form has multiple HTML element with same id so this is wrong. Now if you require to search data with two different inputs, then you can merge it via JS.

HTML code like:

<form method="get" id="search form" action="/">
<div>
<input type="text" value="" name="tag_one" id="tag_one" />
<input type="text" value="" name="tag_two" id="tag_two" />
<input type="hidden" name="tag" id="tag" value=""/><!--Tag is hidden, combine of tag_one and tag_two-->
<input type="hidden" value="94" name="cat" id="scat" />
<input type="submit" id="search_submit" name="Search" value="Search"/>
</div>
</form>

JS code like:

document.getElementbyId('tag').value = document.getElementbyId('tag_one').value +" "+ document.getElementbyId('tag_two').value;

This is build url like http://yoursite.com/....&tag=abc+xyz. And it will automatically give result arround your tags input.

OR

You can use wordpress provided plugin: https://wordpress.org/plugins/multiple-tags.

Thanks!

2
  • The JS merge solution looks like the way to go, and I fixed the capitalization in getElementById and figured the the quoted space between the values should have been "+" but it's not working for me. The URL still has the tag_one and tag_two, not tag.
    – jpd527
    Jun 3, 2015 at 3:12
  • Got it working! Added the JS code to an onclick function for the submit button.
    – jpd527
    Jun 3, 2015 at 3:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.