WP insert post PHP function and user fields

The wordpress function is used to transfer data programmatically. Standard fields for applying for content, excerpt, title, date and more.

Why there is no documentation, how to send to a custom field. I know that this is possible with a function add_post_meta($post_id, $meta_key, $meta_value, $unique);.

I do not know how to include this in the standard wp_insert_post function. So I ask you all because this is more of a PHP question than a WP question. Below is the PHP code to send the message.

<?php 
$my_post = array(
     'post_title' => $_SESSION['booking-form-title'],
     'post_date' => $_SESSION['cal_startdate'],
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_type' => 'booking',
  );
  wp_insert_post( $my_post );
  ?>

Any helpers

Wonderful

+3
source share
1 answer

, , wp_insert_post ID , .

- :

<?php 

$my_post = array(
    'post_title' => ...
);

$new_post_id = wp_insert_post( $my_post );

add_post_meta($new_post_id, $meta_key, $meta_value, $unique);

?>

,

+10

Source: https://habr.com/ru/post/1790051/


All Articles