Ok… So I know how to get both a dropdown for categories and tags into a form. But how do I make the form populate both choices when I hit submit? So that the page it takes you to is something like:
I know that I could type that into the address bar and it will work, just can’t figure out how to do so via two dropdowns in a form.
Any help would be greatly appreciated.
Make sure the method attribute for the form is set to get, and the form elements have the names “cat” and “tag”,and then it will appear in the URL like..:
<form method="get"> <input name="tag" /> <input name="cat" /> <input type="submit" /> </form>
Obviously you already have the dropdowns sorted.
I’ve already tried that… it only goes for whichever dropdown is listed first in the form. It doesn’t combine like that. If it were only that easy….
Can you post your form up? It should be something like this:
<form method="get"> <select name="cat"> <option>1</option> <option>2</option> <option>3</option> </select> <select name="tag"> <option>3</option> <option>5</option> <option>6</option> </select> <input type="submit" /> </form>
then this would append:
Ok, to get the tag dropdown, I followed the instructions here…
<form action="<?php bloginfo('url'); ?>/" method="get"> <?php wp_dropdown_categories('show_count=1&hierarchical=1'); ?> <select name="tag-dropdown"> <option value="#">Select Media</option> <?php dropdown_tag_cloud('number=0&order=asc'); ?> </select> <input type="submit" value="View" /> </form>
then the above goes in my template. the result is trying to do what i need it do, but it is also adding a lot of other stuff to the url. I can’t figure out in that hack code for tag dropdowns to remove it…
Can you give an example of the URL this is giving?
Also can you post a HTML view source of the FORM so we can see it when it’s parsed.
that is what it outputs.
as for the html view source of the form…I’m not sure I get what you mean there. I posted the html source code for the form above…
When you visit the page in your browser click view, then click pagesource, (ctrl+u shortcut in Firefox) then copy the form and paste it.
This way we can see it after it the php is parsed by the browser
<form action="mydomain.com" method="get"> <select name='cat' id='cat' class='postform' > <option class="level-0" value="3" selected="selected">Sherlock Holmes (2)</option> <option class="level-0" value="4">How To Train Dragon (1)</option> </select> <select name="tag-dropdown"> <option value="#">Select Media</option> <option value='http://?tag=30-sheets'>30 Sheets (1)</option> <option value='http://?tag=mall-kiosks'>Mall Kiosks (1)</option></select> <input type="submit" value="View" /> </form>
Hm i’m not too sure on how the dropdown function is working, but I can think of one possibly fix, if you try adding:
$tag_link = str_replace("http://?", "", "$tag_link");
straight after the line (found in function dropdown_generate_tag_cloud)
$tag_link = clean_url($tag_links[$tag]);
What’s the url like after the modification, does it change it at all
didn’t change at all…
I’ve noticed from the url that it is putting the name of the <select> for the tag dropdown in there. but if i simply remove the name it doesn’t work. I’ve been trying to mod different parts and I can get things to disappear, but not the right stuff, etc…
i’ve narrowed it down to how the tag_link section is formed… I’m just not good enough with this code to figure it out..
- The topic ‘Searching tags and categories via dropdowns’ is closed to new replies.