I've set a default post category under Settings -> Writing. I've got a front end page that allows user to create their own post. I'm using the following code to display the categories in a drop down:
<?php
$args = array(
'type' => 'post',
'hide_empty' => 0
);
$categories = get_categories( $args );
?>
<select name="category_name">
<?php
foreach($categories as $category){
if ($category->name != 'Uncategorized') {
if($action=="edit"){
$selected_category = get_the_category($post_id);
$selected_category = $selected_category[0]->cat_name;
if($category->name==$selected_category){
echo '<option value="'.$category->term_id.'" selected> '.$category->name.'</option>';
}else{
echo '<option value="'.$category->term_id.'"> '.$category->name.'</option>';
}
}else{
echo '<option value="'.$category->term_id.'"> '.$category->name.'</option>';
}
}
}
?>
This works fine but I'd like to set the category->term_id as selected when that ID equals the category selected in my settings page. Is this possible?
Thanks!