Support » How-To and Troubleshooting » [Resolved] Is the new dropdown_categories working?

[Resolved] Is the new dropdown_categories working?

  • Trying to use the recommended
    <?php wp_dropdown_categories(); ?>
    in a 2.3 test install. It does nothing. I mean it displays the categories but nothing happens when selecting any of them, it does’nt go to the category listing/archive.

    Any known bugs…?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator Samuel Wood (Otto)


    WordPress.org Tech Dude

    Errr… It’s not supposed to do anything when you select them. What did you expect it to do?

    If you want it to automatically do something, you need to add your own Javascript to do that, like the Categories widget has.

    Maybe I am naive… but I expected that when I “select” a category from the dropdown list – it will take me to that category’s archive.

    OK, I looked at the widget in the wp-includes/widgets.php, now I see what you meant. Not sure I can copy from there but will try something.


    The widget for categories that you can use in 2.3.1 has the option for a dropdown and it works fine at my site.

    Moshu, here’s the working dropdown categroy for WordPress 2.3.x that I’ve configured on my blog, you can modify parameters as you like:

    <form action="<?php bloginfo('url'); ?>" method="get"><?php wp_dropdown_categories('orderby=name&order=ASC&show_count=1&hierarchical=1&show_option_all=Category Archives'); ?><input type="submit" name="submit" size="40" value="Go" /></form>

    OK, with some help from Otto I have solved this: you need the JS after the template tag:

    <li id="categories"><h2><?php _e('POSTS BY CATEGORIES'); ?></h2>
    	<?php wp_dropdown_categories('show_option_none=Select category'); ?>
    <script type="text/javascript"><!--
        var dropdown = document.getElementById("cat");
        function onCatChange() {
    		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    			location.href = "<?php echo get_option('home');
        dropdown.onchange = onCatChange;

    The JavaScript is taken from the WP widgets file…

    Moshu, why do you want to add JS? When you can get full working dropdown with the code, I posted above!

    This is just a query only.

    Rok,your code doesnt work for me. I cant just select a dropdown item and automatically jump, I still have to click the “Go” button. Im in Safari.

    Moshu, your code DOES work though, thanks!! 🙂

    However, now I’m trying to get tricky, and have FOUR dropdowns, each one for a different category, and of course each using this JS solution. However, wp_dropdown_categories automatically assigns each one the name and id of “cat”, so it only recognizes the first one. Does anyone know of a way to make it work? 🙂



    Rok,your code doesnt work for me.

    It won’t, ‘coz it’s based on select and submit function. See the last line of the code.

    <input type="submit" name="submit" size="40" value="Go" />

    Right. But you were wondering why Moshu would want to use JS when your solution would work without it. Which it doesnt, not as Moshu was attempting to make it work at least, but just as a regular old dropdown with a submit button.

    Thanks for this; it’s just what I needed, too. Having a drop-down and then a submit button seems an inelegant solution for the user; much better to have the category auto-select.

    Moshu…you rock!!! This isn´t the first time I find a solution thanks to your post.

    regards, chavo.

    I tried using the code chunk provided and it’s not firing the onChange event for some reason.

    I’m getting no errors… so I’m not sure where to go with this.

    I’m new to the WP world, so I don’t know what all is going on when the page is loaded. In theory it should be working.

    I’m not sure if anyone is still keeping up with this thread, but moshu, thank you for this! It’s just what I needed. My only question is how can I use your code and have the categories be alphabetized within the drop down? I know it’s something simple but I’m a little shaky with everything wordpress-related and I can’t seem to get it. I’ve read a million things on here and am getting more confused for something that is probably so simple to change. Any help would be appreciated!

    Hello, It´s me again. I´m tryng the dropdown menu with the child_of parameter. I want that when I select a sub-category item its redirects to siteurl/category/parent_category/child.

    So, if the parent category is “links”, when I select the “links_2” sub-category from the dropdown menu list I want that the url looks like this: site_url/category/links/links_2.

    If I put a list_category in the sidebar and I click in a sub-category, the url looks like the url I want, but when I select a sub-category from the dropdown the url looks like this: siteurl/?cat=#
    note: # = sub-category ID.

    Any ideas about how to change it?
    Thanks in advance.

    ps: sorry for my bad english.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Resolved] Is the new dropdown_categories working?’ is closed to new replies.