1
我目前工作的地方,我需要從前端創建帖子。 這是我的代碼,從wordpress網站的前端創建自定義帖子。添加標籤,當在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>
我顯示我的網頁上的所有標籤,但我不知道如何將它們分配到崗位。 目前我能夠使用我的代碼創建帖子,但我需要的只是添加標籤到我的文章。
有什麼想法?
不錯。謝謝 – WPguy