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):
<?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);
endif;
?>
File 2 (submit-resume-form.php):
<?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');
endif;
What am I doing wrong? It doesn’t save the selections!
Thanks in advance.
First in checkbox value use taxonomy id not the name of taxonomy.
For save more than one taxonomy relation related to a post in
wp_term_relationship
table use“wp_set_object_terms” will save checked taxonomy value to “wp_term_relationship” table with post id.