【发布时间】:2012-03-30 01:50:03
【问题描述】:
我使用 wordpress 创建了一个返回标题和描述的表单。我需要返回更多自定义字段。我在互联网上搜索过,发现很多答案都没有很好地解释它,他们最终没有为我工作。该表单将返回包含标题、描述和已填写的自定义字段的帖子。谢谢!
if('POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter the wine name';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo 'Please enter some notes';
}
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_Blog_URL' => $URL,
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc.
'post_type' => 'post' //'post',page' or use a custom post type if you want to
);
add_post_meta($post_id, $meta_key, 'URL' , $unique);
//SAVE THE POST
$pid = wp_insert_post($new_post);
//REDIRECT TO THE NEW POST ON SAVE
$link = get_permalink( $pid );
wp_redirect( $link );
} // 结束整个表单的 IF 语句
do_action('wp_insert_post', 'wp_insert_post');
提交您自己的!
<div id="postbox">
<form id="new_post" name="new_post" method="post" action="" class="" enctype="multipart/form-data">
<!-- post name -->
<fieldset name="name">
<label>Name of the Article</label>
<input type="text" id="title" value="" tabindex="1" size="20" name="title" />
</fieldset>
<!-- post Content -->
<fieldset class="content">
<label for="description">Description</label>
<textarea id="description" tabindex="15" name="description"></textarea>
</fieldset>
<button type="submit">Submit</button>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( 'new-post' ); ?>
</form>
【问题讨论】:
标签: wordpress