Support » Fixing WordPress » wp_dropdown_categories generating url ID number instead of slug

  • Hi all, this problem has me going nuts now.
    if you choose a category in the category filter box, the parent categories generate an ID number instead of the category slug in the URL. It’s not SEO im worried about, it’s that the WP_Query doesn’t work if it doesnt generate a proper URL. So the box for sorting next to the category will not work.
    The categories within the hierarchy works fine.

    <form action="<?php bloginfo('url'); ?>/" method="get">
                        $select = wp_dropdown_categories('show_option_all=Filter by Category...&exclude=1,31,21&show_count=1&hide_empty=1&depth=3&hierarchical=false&orderby=name&echo=0&selected=6&taxonomy=category');
                        $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
                        echo $select;
                        <noscript><input type="submit" value="View" /></noscript>


Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter cixxy




    i know that’s quite late for an answer, but i’m quite fresh with wp. hope to help you or at least somebody else 🙂

    my idea:
    1) create child class for Walker_CategoryDropdown with little modified start_el function:

    class my_Walker_CategoryDropdown extends Walker_CategoryDropdown {
    	function start_el(&$output, $category, $depth, $args) {
    		$pad = str_repeat('&nbsp;', $depth * 3);
    		$cat_name = apply_filters('list_cats', $category->name, $category);
    		$output .= "\t<option class=\"level-$depth\" value=\"".$category->slug."\"";
    		if ( $category->term_id == $args['selected'] )
    			$output .= ' selected="selected"';
    		$output .= '>';
    		$output .= $pad.$cat_name;
    		if ( $args['show_count'] )
    			$output .= '&nbsp;&nbsp;('. $category->count .')';
    		if ( $args['show_last_update'] ) {
    			$format = 'Y-m-d';
    			$output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp);
    		$output .= "</option>\n";

    2) call wp_dropdown_categories with the new Walker object (not documented)

                'walker' => new my_Walker_CategoryDropdown


    This post helped me so much!! I tried everything from any forum I could find and nothing worked…except this! What I am trying to do is understand the code a little bit.

    I simplified the output a little by removing the counter and the update…the code now looks like:

    Everything else looks pretty self-explanatory (to me), but what does the $pad variable do? I see the repeat, the   and the $depth parameter, but I have no idea what it’s doing.

    Just curious…thanks,

    glad to help mate.

    you’re right. pad = padding. it just moves the line one space to right to show deep of entity.

    look here to read sth about the function:



    Thanks for the clarification 🙂


    Thanks numer I used your code to create a drop down to show all the post from particular taxonomy. I wrote a small tutorial for this. Read it on my blog.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_dropdown_categories generating url ID number instead of slug’ is closed to new replies.