Im working on a custom walker for a custom taxonomy dropdown on a post type.
By default the Walker_CategoryDropdown, will select the the element that matches the id specified in $args['selected'].
Instead I want the walker to:
- get the identity of the taxonomy term it is evaluating,
- see if this taxonomy term has been assigned to the current post
- make that the selected element.
class my_Walker_CategoryDropdown extends Walker_CategoryDropdown {
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
$pad = str_repeat(' ', $depth * 3);
/** This filter is documented in wp-includes/category-template.php */
$cat_name = apply_filters( 'list_cats', $category->name, $category );
$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
if ( $category->term_id == $args['selected'] ) // THIS CONDITION HERE NEEDS MODIFIED
$output .= ' selected="selected"';
$output .= '>';
$output .= $pad.$cat_name;
if ( $args['show_count'] )
$output .= ' ('. number_format_i18n( $category->count ) .')';
$output .= "</option>\n";
}
}