我构建了一个表单,使用户能够从前端发布。我试图让它通过 wp_set_object_terms 分类法,因为我使用自定义帖子类型和自定义分类法。这是我的代码:
if(isset ($_POST['submit_offer'])=='submit'){
$user_id = get_current_user_id();
$args=array(
'post_author' => $user_id,
'post_title' => $_POST['job_title'],
'post_content' => $_POST['post_content'],
'post_excerpt' => $_POST['job_field'],
'meta_input' => array(
'points_amount' => $_POST['post_points'],
),
'post_status' => 'publish',
'post_type' => 'job_offers',
);
// get post id
$post_id = wp_insert_post($args);
$job_tax = array ( 44 , 45 );
wp_set_object_terms( $post_id , $job_tax, 'field_of_work' );
}
Run Code Online (Sandbox Code Playgroud)
而且它不起作用!!!!