How to insert post meta values ​​in wordpress

How to embed message metadata when adding a message? I am using the wp_insert_post function to insert a message. To use the add_post_meta function, we need to specify the message identifier. How to add values ​​while typing a message? Is there any way to do this !?

hi - dj

+3
source share
2 answers

Suppose you created an array to insert post

$new_post = array(
        'post_title'   => $title,
        'post_content' => $content,
        'post_type'    => $type,
    'post_status'  => $status           
    );

get the new inserted post_id with

$id = wp_insert_post($new_post);

then paste the values ​​into the wp_postmeta table, passing parameters such as post_id, meta_key, meta_value

update_post_meta($id,'total_payments',$amount);
update_post_meta($id,'downcount',$downcount);

try it.

+20
source

. . Post, wp_insert_post. .

0

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


All Articles