【发布时间】:2020-06-04 21:54:13
【问题描述】:
我正在运行这个函数:
function create_post() {
ob_start();
if(isset($_POST['new_post']) == '1') {
$post_title = $_POST['post_title'];
$post_category = $_POST['cat'];
$post_content = $_POST['post_content'];
$new_post = array(
'ID' => '',
'post_author' => $user->ID,
'post_category' => array($post_category),
'post_content' => $post_content,
'post_title' => $post_title,
'post_status' => 'publish'
);
$post_id = wp_insert_post($new_post);
// This will redirect you to the newly created post
$post = get_post($post_id);
wp_redirect($post->guid);
}
?>
<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title" placeholder="Voer hier de titel van het nieuwsbericht in"/>
<?php wp_dropdown_categories('orderby=name&hide_empty=0&exclude=1&hierarchical=1'); ?>
<textarea rows="5" name="post_content" cols="66" id="text-desc" placeholder="Voer hier de tekst van het bericht in"></textarea>
<p>
Kies hieronder de afbeelding van het nieuwsbericht.
</p>
<input type="file" id="featured_image" name="featured_image" accept="image/*">
<br/><br/>
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Nieuwsbericht aanmaken"/>
</form>
<?php
return ob_get_clean();
}
add_shortcode('create_post', 'create_post');
它会在提交时创建一个帖子,但是如何将输入 type="file" 中选择的图像添加为特色图像?
我还想用这个前端表单填写 ACF 字段。
【问题讨论】:
标签: wordpress image post upload frontend