我想插入或您可以说从我的前端表单中选择自定义帖子类型中的预定义类别。我不知道我在哪里丢失了任何代码。请帮我解决这个问题。。。
下面是我的代码。提前谢谢!!
<?php
global $wpdb;
$user_id = get_current_user_id();
if(!empty($user_id)){
$jaddress = wp_strip_all_tags( $_POST[\'jobaddress\'] );
$jobcity = wp_strip_all_tags( $_POST[\'jobcity\'] );
$jobpostal = wp_strip_all_tags( $_POST[\'jobpostal\'] );
$jobmobile = wp_strip_all_tags( $_POST[\'jobmobile\'] );
$post_information = array(
\'post_title\' => wp_strip_all_tags( $_POST[\'jobtitle\'] ),
\'post_content\' => $_POST[\'jobdescription\'],
\'post_category\' => array($_POST[\'jobtype\']),
\'post_type\' => \'employment\',
\'post_author\' => $user_id,
\'post_status\' => \'pending\'
);
$pid = wp_insert_post( $post_information );
wp_set_post_terms($pid,array($_POST[\'jobtype\']),\'jobtype\',true);
add_post_meta($pid, \'wpcf-jobaddress\', $jaddress, true);
add_post_meta($pid, \'wpcf-jobparishcity\', $jobcity, true);
add_post_meta($pid, \'wpcf-jobpostalcode\', $jobpostal, true);
add_post_meta($pid, \'wpcf-jobmobilenumber\', $jobmobile, true);
}else{
$jaddress = wp_strip_all_tags( $_POST[\'jobaddress\'] );
$jobcity = wp_strip_all_tags( $_POST[\'jobcity\'] );
$jobpostal = wp_strip_all_tags( $_POST[\'jobpostal\'] );
$jobmobile = wp_strip_all_tags( $_POST[\'jobmobile\'] );
$post_information = array(
\'post_title\' => wp_strip_all_tags( $_POST[\'jobtitle\'] ),
\'post_content\' => $_POST[\'jobdescription\'],
\'post_category\' => array($_POST[\'jobtype\']),
\'post_type\' => \'employment\',
\'post_status\' => \'pending\'
);
$pid = wp_insert_post( $post_information );
add_post_meta($pid, \'wpcf-jobaddress\', $jaddress, true);
add_post_meta($pid, \'wpcf-jobparishcity\', $jobcity, true);
add_post_meta($pid, \'wpcf-jobpostalcode\', $jobpostal, true);
add_post_meta($pid, \'wpcf-jobmobilenumber\', $jobmobile, true);
}?>
<div class="doublefield">
<p><span class="select-style"><?php wp_dropdown_categories( \'show_option_none=Job Type&taxonomy=jobtype\' ); ?><!--<select id="jobtype" name="jobtype"><option value="Permanent">Permanent</option><option value="Temporary">Temporary</option></select>--></span></p>
<p><span class="select-style"><select id="joblocation" name="joblocation"><option value="United States">United States</option><option value="India">India</option><option value="China">China</option></select></span></p>
</div>