Background
<我使用一个前置表单,通过使用带有自定义分类法(调用类型)的wp\\u update\\u post to a custom post type(call),向元框提交数据然后,它还更新了这篇文章的术语和分类法代码对此完全有效这是工作代码
//update post
$post_id = wp_update_post($post_information);
if($post_id)
{
// Update Custom Meta
update_post_meta($post_id, \'_call_16\', $_POST[\'call_16\']);
update_post_meta($post_id, \'_call_17\', $_POST[\'call_17\']);
update_post_meta($post_id, \'_call_18\', $_POST[\'call_18\']);
update_post_meta($post_id, \'_call_19\', $_POST[\'call_19\']);
// Update Custom Meta
update_post_meta($post_id, \'_call_20\', $_POST[\'call_20\']);
// Update call "terms" or taxonomy
$term_ids = array( 3, 14 );
$taxonomy = \'call-type\';
wp_set_object_terms( $post_id, $term_ids, $taxonomy );
// Redirect
wp_redirect( \'$url\' );
}
?>
Html来自
...
<div class="form-group">
<label class="w-25" for="call_16">Is site Visit Required</label>
<select class="w-50 px-1 py-1" name="call_16">Site Visit </p>
<option value=""></option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
...
The Problem
我希望代码根据提交条目的值更新术语。
The desired result is.
- 如果$\\u POST[\'call\\u 16\']=No 将术语更改为18.
- 如果$\\u POST[\'call\\u 16\']=Yes 将术语更改为14.
The code I have try
//update post
$post_id = wp_update_post($post_information);
if($post_id)
{
// Update Custom Meta
update_post_meta($post_id, \'_call_16\', $_POST[\'call_16\']);
update_post_meta($post_id, \'_call_17\', $_POST[\'call_17\']);
update_post_meta($post_id, \'_call_18\', $_POST[\'call_18\']);
update_post_meta($post_id, \'_call_19\', $_POST[\'call_19\']);
// Update call terms or taxonomy
if (isset($_POST[\'call_16\']) == \'No\' ) {
$term_ids = array( 3, 18 );
$taxonomy = \'call-type\';
wp_set_object_terms( $post_id, $term_ids, $taxonomy );
// Redirect
wp_redirect( \'$url2\' );
}
else {
$term_ids = array( 3, 14 );
$taxonomy = \'call-type\';
wp_set_object_terms( $post_id, $term_ids, $taxonomy );
// Redirect
wp_redirect( \'$url\' );
}
}
?>
如果可能的话,请有人提出建议,并详细说明如何做到这一点。
。