<form method="post">
<input type="text" name="title" /> //Title
<input type="text" name="desc" /> //Description
<input type="text" name="age" /> //Age autor
</form>
此代码在新文章中添加标题和说明。但是如何添加自定义日期?恩。年龄输入。
$title = $_POST['title'];
$desc = $_POST['desc'];
$date = array(
'post_title' => $title,
'post_content' => $desc,
'post_status' => 'publish'
);
wp_insert_post($date);
答案 0 :(得分:2)
查看自定义元框。这是一篇关于它的优秀文章http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/
允许您保存自定义字段的初始函数是add_post_meta()
。例如:
add_post_meta( $post_id, $meta_key, $new_meta_value, true );
如果自定义元框不是您要查找的内容,则可以执行以下操作:
$post_ID = wp_insert_post($date);
add_post_meta( $post_ID, 'custom_field', 'content for custom field', true );
答案 1 :(得分:1)
wp_insert_post将返回一个ID。然后,您将使用它来添加post meta。
https://codex.wordpress.org/Function_Reference/wp_insert_post https://codex.wordpress.org/Function_Reference/add_post_meta
E.g。
$id = wp_insert_post( $date );
$age = {GET AND SANITIZE YOUR AGE INPUT}
add_post_meta( $id, 'age', $age, true );