I have the bit of code below and I would like uses to select multiple options in the "select multiple" box and for these all to be added into the database. At the moment only 1 of the values that is selected is entered. I am a noob with this sort of thing so an in need of help to progress with the project.
Thanks for any help!
function ProjectTheme_get_categories($taxo, $selected = "", $include_empty_option = "", $ccc = "")
{
$args = "orderby=name&order=ASC&hide_empty=0&parent=0";
$terms = get_terms( $taxo, $args );
$ret = '<select multiple size="20" name="'.$taxo.'_cat" class="'.$ccc.'" id="scrollselect '.$ccc.'">';
if(!empty($include_empty_option)) $ret .= "<option value=''>".$include_empty_option."</o ption>";
if(empty($selected)) $selected = -1;
foreach ( $terms as $term )
{
$id = $term->term_id;
$ret .= '<option '.($selected == $id ? "selected='selected'" : " " ).' value="'.$id.'">'.$term->name.'</option>';
$args = "orderby=name&order=ASC&hide_empty=0&parent=".$id;
$sub_terms = get_terms( $taxo, $args );
foreach ( $sub_terms as $sub_term )
{
$sub_id = $sub_term->term_id;
$ret .= '<option '.($selected == $sub_id ? "selected='selected'" : " " ).' value="'.$sub_id.'"> | '.$sub_term->name.'</option>';
$args2 = "orderby=name&order=ASC&hide_empty=0&parent=".$sub_id;
$sub_terms2 = get_terms( $taxo, $args2 );
foreach ( $sub_terms2 as $sub_term2 )
{
$sub_id2 = $sub_term2->term_id;
$ret .= '<option '.($selected == $sub_id2 ? "selected='selected'" : " " ).' value="'.$sub_id2.'"> |
'.$sub_term2->name.'</option>';
}
}
}
$ret .= '</select>';
return $ret;
}
Here is another section of the code where the user interacts with that form
<li><h2><?php echo __('Category', 'ProjectTheme'); ?>:</h2>
<p><?php echo ProjectTheme_get_categories("project_cat",
!isset($_POST['project_cat_cat']) ? (is_array($cat) ? $cat[0]->term_id : "") : $_POST['project_cat_cat']
, __("Select Category","ProjectTheme"), "do_input"); ?></p>
</li>
Additional code that handles the submit function of the form
do_action('ProjectTheme_post_new_post_post',$pid);
if(isset($_POST['project_submit1']))
{
$project_title = trim($_POST['project_title']);
$project_description = nl2br($_POST['project_description']);
$project_category = $_POST['project_cat_cat'];
$project_location = trim($_POST['project_location_cat']);
$project_tags = trim($_POST['project_tags']);
$price = trim($_POST['price']);
$project_location_addr = trim($_POST['project_location_addr']);
$end = trim($_POST['ending']);
update_post_meta($pid, 'finalised_posted', '0');
//--------------------------------
$projectOK = 1;
if(empty($project_title)) { $projectOK = 0; $MYerror['title'] = __('You cannot leave the project title blank!','ProjectTheme'); }
if(empty($project_category)) { $projectOK = 0; $MYerror['cate'] = __('You cannot leave the project category blank!','ProjectTheme'); }
if(empty($project_description)) { $projectOK = 0; $MYerror['description'] = __('You cannot leave the project description blank!','ProjectTheme'); }
//--------------------------------
$project_category2 = $project_category;
$my_post = array();
$my_post['post_title'] = $project_title;
$my_post['post_status'] = 'draft';
$my_post['ID'] = $pid;
$my_post['post_content'] = $project_description;
$term = get_term( $project_category, 'project_cat' );
$project_category = $term->slug;
$term = get_term( $project_location, 'project_location' );
$project_location = $term->slug;
wp_update_post( $my_post );
wp_set_object_terms($pid, array($project_category),'project_cat');
wp_set_object_terms($pid, array($project_location),'project_location');
wp_set_post_tags( $pid, $project_tags);