Support » Fixing WordPress » Searching tags and categories via dropdowns

  • Resolved Kahil

    (@kahil)


    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:

    mysite.com/?cat=3&tag=my-tag

    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.

Viewing 15 replies - 1 through 15 (of 16 total)
  • 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:

    mysite.com/page.php?cat=value&tag=value

    Ok, to get the tag dropdown, I followed the instructions here…

    How to: Display your WordPress Tags in a Drop-Down Menu

    <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.

    mydomain.com/?cat=3&tag-dropdown=http%3A%2F%2F%3Ftag%3D30-sheets

    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…

    30-sheets is the tag slug fyi…

    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&nbsp;&nbsp;(2)</option>
    	<option class="level-0" value="4">How To Train Dragon&nbsp;&nbsp;(1)</option>
    </select>
        <select name="tag-dropdown">
    	<option value="#">Select Media</option>
    		<option value='http://?tag=30-sheets'>30&nbsp;Sheets (1)</option>
    
    	<option value='http://?tag=mall-kiosks'>Mall&nbsp;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]);

    didn’t work… 🙁

    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..

    Yes it is because http://? is being appended to the tag link name for some reason, i’ll have a look into the function later if i get chance

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Searching tags and categories via dropdowns’ is closed to new replies.