I'm displaying a drop down list of categories on a front end form using this code. I want the category which is set in the post to be selected when the form loads but this isn't working. What wrong with the code?
$category = get_the_category();
$selected = 0;
if ( $category ) {
$selected = $category[0]->cat_name;
}
wp_dropdown_categories( 'hierarchical=1&hide_empty=0&orderby=name&id=cat&show_count=0&title_li=&use_desc_for_title=1&class=cat requiredField&selected=' . $selected );