Wordpress 使用wp_insert_post()创建帖子后获取帖子ID
似乎在任何地方都找不到明确的答案。在使用wp_insert_post()创建帖子之后,我需要获取帖子的IDWordpress 使用wp_insert_post()创建帖子后获取帖子ID,wordpress,Wordpress,似乎在任何地方都找不到明确的答案。在使用wp_insert_post()创建帖子之后,我需要获取帖子的ID 之后,如何获取刚刚创建的$log\u项的IDpost?请将post ID存储到临时变量中: $log_item = array( 'post_title' => $title, 'post_content' => '', 'post_status' => 'publish',
之后,如何获取刚刚创建的
$log\u项的ID
post?请将post ID存储到临时变量中:
$log_item = array(
'post_title' => $title,
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'log-item',
'meta_input' => array(
// 'wpcf-date-checked' => '',
// 'wpcf-checked-by' => '',
'wpcf-belongs-to-id' => $parent_id,
),
);
// You can also get the new post ID after inserting a new post:
$post_id = wp_insert_post( $log_item , $wp_error );
如需更多帮助:
$log_item = array(
'post_title' => $title,
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'log-item',
'meta_input' => array(
// 'wpcf-date-checked' => '',
// 'wpcf-checked-by' => '',
'wpcf-belongs-to-id' => $parent_id,
),
);
// You can also get the new post ID after inserting a new post:
$post_id = wp_insert_post( $log_item , $wp_error );