我正在使用apptheme jobroller主题,并试图操纵其编辑简历页面。我想展示一个特定的分类法(resume_specialities) 作为一组多个复选框,使用户可以选中多个选项。我只是不知道如何保存这些多个选择。在三个不同的php文件中有三段相关代码。以下代码是它们的相关部分:
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 (提交简历表单.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 (提交简历流程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;
我做错了什么?它不会保存选择!提前谢谢。