0
我正在使用此前端代碼創建帖子。目前它確實創建了一個帖子,但唯一可行的是標題。從前端開始工作
我也有一些自定義的metabox有一些字段(more_info,priority和duedate和)在我的文章中,但我不確定是否將它們正確地放入數組中。請注意,在後端這些額外的領域工作得很好。
這裏是我的代碼:
<?php
if('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action'])) {
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter a title';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
}
// Add the content of the form to $post as an array
$post = array(
'post_title' => $title,
'post_content' => $description,
'more_info' => $more_info,
'priority' => $priority,
'duedate' => $duedate,
'post_category' => $_POST['cat'],
'post_status' => 'publish',
'post_type' => $_POST['post']
);
wp_insert_post($post);
}
do_action('wp_insert_post', 'wp_insert_post');
?>
<form action="" id="new_post" method="post">
<label for="title">Task Name </label>
<input type="text" id="title" name="title" value="" />
<label for="minfo">Additional information</label>
<textarea name="minfo" id="minfo" value=""></textarea>
<label>Due date</label>
<input type="text" id="duedate" name="duedate" />
<strong>Priority</strong>
<label><input type="radio" name="priority" value="low" id="low">Low</label>
<label><input type="radio" name="priority" value="normal" id="normal" checked>Normal</label>
<label><input type="radio" name="priority" value="high" id="high">High</label>
<label><input type="radio" name="priority" value="urgent" id="urgent">Urgent</label>
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="cat" id="cat" value="<?php echo $cat_id = get_query_var('cat'); ?>" />
<input type="hidden" name="post_type" id="post_type" value="post" />
<input type="hidden" name="action" value="post" />
<?php wp_nonce_field('new-post'); ?>
</form>
任何援助將是真棒。
我已經有「職位」這在後端(看起來像這樣i.imgur.com/URRFHpO.png)正常工作的自定義metabox。它只是試圖從前端(從我的一個模板中的表單)創建帖子。 – PHPnoob