How to save a multiple checkbox array into a non-hierarchical taxonomy


I’m using apptheme jobroller theme and trying to manipulate its Edit Resume page. I want to show a specific taxonomy (resume_specialities) as a set of multiple checkboxes and enable users to check multiple selections. I just don’t know how to save these multiple selections. There are 3 pieces of related code in three different php files. The codes below are the relative parts of them:

File 1 (tpl-edit-resume.php):

if ($resume_id>0) :

    // Get job details
    $resume_details = get_post($resume_id);

    if (!isset($_POST['save_resume'])) :
        // Set post data
        $terms = wp_get_post_terms($resume_id, 'resume_specialities');
        $terms_array = array();
        foreach ($terms as $t) $terms_array[] = $t->name;
        $posted['specialities'] = implode(',', $terms_array);


File 2 (submit-resume-form.php):

$specs_array = explode(',', $posted['specialities']);

<p><?php _e('Specialties', APP_TD); ?></p>
<?php $all_specialities = get_terms( 'resume_specialities', array( 'hide_empty' => false ) ); ?>

<?php foreach ($all_specialities as $single_speciality) : ?>
    <label for="specialities">
    <input type="checkbox" name="specialities[]"
        id="speciality-<?php echo $single_speciality->term_id; ?>"  
        value="<?php echo $single_speciality->name; ?>"
    <?php if ( in_array( $single_speciality->name, $specs_array ) ) echo ' checked="checked"'; ?> />
    <?php echo $single_speciality->name; ?></label>
    <br />
<?php endforeach; ?>

File 3 (submit-resume-process.php):

if (isset($posted['specialities'])) :
    $thetags = explode(',', $posted['specialities']);
    $thetags = array_map('trim', $thetags);

    if (sizeof($thetags)>0) wp_set_object_terms($resume_id, $thetags, 'resume_specialities');           

What am I doing wrong? It doesn’t save the selections!
Thanks in advance.

Genzo 10 years 2013-06-17T20:11:42-05:00 0 Answers 73 views 0

Leave an answer