답변:
다음과 같이 wp_insert_post () 및 add_post_meta () 를 사용하십시오.
// insert the post and set the category
$post_id = wp_insert_post(array (
'post_type' => 'your_post_type',
'post_title' => $your_title,
'post_content' => $your_content,
'post_status' => 'publish',
'comment_status' => 'closed', // if you prefer
'ping_status' => 'closed', // if you prefer
));
if ($post_id) {
// insert post meta
add_post_meta($post_id, '_your_custom_1', $custom1);
add_post_meta($post_id, '_your_custom_2', $custom2);
add_post_meta($post_id, '_your_custom_3', $custom3);
}
'meta_input' => ['_your_custom_1' => $custom1, '_your_custom_2' => custom2]
위 의 @webaware 에 대한 훌륭한 답변 외에도 wordpress 4.4.0 부터 wp_insert_post 호출을 통해 처리 할 수 있습니다 .
$post_id = wp_insert_post(array (
'post_content' => $content,
'post_title' => $title,
'post_type' => 'your_custom_post_type',
'post_status' => 'publish',
// some simple key / value array
'meta_input' => array(
'your_custom_key1' => 'your_custom_value1',
'your_custom_key2' => 'your_custom_value2'
// and so on ;)
)
));
if ($post_id) {
// it worked :)
}
이것은 Gravity Forms 플러그인을 사용하여 매우 쉽게 달성 할 수 있습니다 . 백엔드에서 사용자 정의 게시물 유형을 채우는 양식을 작성할 수 있습니다. 이 게시물은 초안 또는 게시 된 것으로 표시되도록 설정할 수 있습니다. 사용자 정의 필드를 추가하는 데 문제가 없습니다. 제 경우에는 고객 평가를 수집하는 데 사용했습니다.