如何在wordpress中插入帖子元值

问题描述:

如何在添加帖子时插入帖子元值?我正在使用 wp_insert_post 函数来插入帖子.要使用add_post_meta"函数,我们需要指定帖子 ID.如何在插入帖子时添加值?有没有办法做到这一点!?

How to insert post meta values while adding a post? I am using wp_insert_post function to insert the post. For using the "add_post_meta" function, we need to specify the post ID. How can I add the values at the time of inserting post? Is there any way to do this!?

问候 - DJ

我想你已经创建了一个数组来插入帖子

i suppose you have created an array to insert post

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

获取新插入的 post_id

get the new inserted post_id with

$id = wp_insert_post($new_post);

然后通过传递 post_id、meta_key、meta_value 等参数在 wp_postmeta 表中插入值

then insert values in wp_postmeta table by passing parameters like post_id, meta_key, meta_value

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

试试看.