WP插入后PHP函数和自定义字段 [英] WP insert post PHP function and Custom Fields
问题描述
字preSS功能用于编程提交数据。标准领域提交incude的内容,摘录,标题,日期等等。
The wordpress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more.
有什么是没有文档是如何提交到自定义字段。我知道这是可能的 add_post_meta($ POST_ID,$ meta_key,$ meta_value,$唯一的);
功能。
What there is no documentation for is how to submit to a custom field. I know it is possible with the add_post_meta($post_id, $meta_key, $meta_value, $unique);
function.
我不知道的是如何包括到标准wp_insert_post功能。所以我问你所有的原因是因为这是一个多WP问题PHP的问题。下面是PHP code提交的帖子。
What I don't know is how to include that into the standard wp_insert_post function. So the reason I ask you all is because this is more of a PHP question than a WP question. Below is the PHP code to submit the post.
<?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 );
?>
任何帮助CHAPS,
Any help chaps,
奇妙
推荐答案
如果你看一下在codeX函数参考,你可以看到, wp_insert_post
收益在 ID
如果POST成功添加到数据库中的职位。
If you look at the functions reference in the codex, you can see that wp_insert_post
returns The ID
of the post if the post is successfully added to the database.
由于这一点,你可以这样做:
Because of that, you can do so:
<?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);
?>
希望这有助于
这篇关于WP插入后PHP函数和自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!