如何在wordpress中插入帖子元值 [英] How to insert post meta values in wordpress
本文介绍了如何在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);
试试看.
这篇关于如何在wordpress中插入帖子元值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文