There is an argument walker
for wp_dropdown_categories()
. It accepts an instance of a custom walker, a class extending Walker_CategoryDropdown
or the generic Walker
.
Let’s create such a class. We have to change just one method.
class WPSE_Cat_Slug_Walker extends Walker_Category
{ function start_el( &$output, $category, $depth, $args, $id = 0 ) {
$pad = str_repeat(' ', $depth * 3);
$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
if ( $category->term_id == $args['selected'] )
$output .= ' selected="selected"';
$output .= '>';
$output .= $pad.$category->slug; // The Slug!
if ( $args['show_count'] )
$output .= ' ('. $category->count .')';
$output .= "</option>\n";
}
}
Now we create an instance of our class …
$wpse_cat_slug_walker = new WPSE_Cat_Slug_Walker;
… and pass it to the dropdown:
$select = wp_dropdown_categories(
array (
'hierarchical' => 1,
'hide_empty' => 0,
'echo' => 0,
'name' => "field_$nextItem",
'id' => $selectID,
'class' => 'categoriesBox',
'walker' => $wpse_cat_slug_walker // the walker
)
);
Note, this is completely untested, just an idea to show you the direction. 🙂