【发布时间】:2014-01-10 16:44:33
【问题描述】:
我目前在一个需要从前端创建帖子的网站工作。 这是我从 wordpress 网站前端创建自定义帖子的代码。
<?php
$postTitleError = '';
if (isset($_POST['submitted']))
{
if(trim($_POST['postTitle']) === '')
{
$postTitleError = 'Please enter a title.';
$hasError = true;
}
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'product',
'post_status' => 'publish'
);
wp_insert_post( $post_information );
}
?>
这是我的 HTML 表单:
<form action="" id="primaryPostForm" method="POST">
<!-- Title -->
<input class="addTitle" type="text" name="postTitle" id="postTitle" class="required" />
<!-- Description -->
<input class="addDescription required" name="postContent" id="postContent" />
<!-- Submit button -->
<button type="submit"><?php _e('Add Product', 'framework') ?></button>
</form>
我在页面上显示了我的所有标签,但我不知道如何将它们分配到帖子中。 目前我可以使用我的代码创建帖子,但我只需要在我的帖子中添加标签。
有什么想法吗?
【问题讨论】:
标签: php html wordpress tags custom-fields