WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Searching tags and categories via dropdowns (17 posts)

  1. Kahil
    Member
    Posted 4 years ago #

    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.

  2. xdesi
    Member
    Posted 4 years ago #

    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.

  3. Kahil
    Member
    Posted 4 years ago #

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

  4. xdesi
    Member
    Posted 4 years ago #

    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

  5. Kahil
    Member
    Posted 4 years ago #

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

    http://wphacks.com/how-to-display-wordpress-tags-dropdown-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...

  6. xdesi
    Member
    Posted 4 years ago #

    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.

  7. Kahil
    Member
    Posted 4 years ago #

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

  8. Kahil
    Member
    Posted 4 years ago #

    30-sheets is the tag slug fyi...

  9. xdesi
    Member
    Posted 4 years ago #

    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

  10. Kahil
    Member
    Posted 4 years ago #

    <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>
  11. xdesi
    Member
    Posted 4 years ago #

    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]);

  12. Kahil
    Member
    Posted 4 years ago #

    didn't work... :(

  13. xdesi
    Member
    Posted 4 years ago #

    What's the url like after the modification, does it change it at all

  14. Kahil
    Member
    Posted 4 years ago #

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

  15. Kahil
    Member
    Posted 4 years ago #

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

  16. xdesi
    Member
    Posted 4 years ago #

    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

  17. Kahil
    Member
    Posted 4 years ago #

    I figured it out!!! That code has way too much in it for what I needed, so I cut it down.

    Here it is...

    <?php
    
    $args = array(
            'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 999,
            'format' => 'array', 'orderby' => 'name', 'order' => 'ASC',
            'exclude' => '', 'include' => '');
    
    $tags = get_tags($args);
    
    ?>
    
    <form action="<?php bloginfo('url'); ?>" method="get">
    <?php wp_dropdown_categories('show_option_none=Select Campain&show_count=1&hierarchical=1'); ?>
            <select id="select-of-tags" name="tag">
                    <option value="">Select Media</option>
    <?php foreach ($tags as $tag) {?>
                    <option value="<?php echo $tag->slug ?>"><?php echo $tag->name ?></option>
    <?php } ?>
            </select>
            <input type="submit" value="View" />
    </form>

Topic Closed

This topic has been closed to new replies.

About this Topic