我有一个自定义的帖子类型books
和3个自定义分类附加到books
. 自定义分类法包括:books-categories
, location
, services_c
. 我应该如何编辑我的表单以使分类法正常工作;我花了三天时间试图解决这个问题,但我做不到。有人能帮我吗?
<?php
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 a title\';
}
if (isset ($_POST[\'description\'])) {
$description = $_POST[\'description\'];
} else {
echo \'Please enter the content\';
}
$tags = $_POST[\'post_tags\'];
// Add the content of the form to $post as an array
$new_post = array(
\'post_title\' => $title,
\'post_content\' => $description,
\'tags_input\' => array($tags),
\'post_status\' => \'draft\', // Choose: publish, preview, future, draft, etc.
\'post_type\' => \'books\' //\'post\',page\' or use a custom post type if you want to
);
//save the new post
$pid = wp_insert_post($new_post);
}
?>
<!-- New Post Form -->
<div id="postbox">
<form id="new_post" name="new_post" method="post" action="">
<!-- post name -->
<p><label for="title">Title</label><br />
<input type="text" id="title" value="" tabindex="1" size="20" name="title" />
</p>
<!-- post Category -->
<p><label for="Category">Category:</label><br />
<p><?php wp_dropdown_categories( \'show_option_none=Category&tab_index=4&taxonomy=books-categories\' ); ?></p>
<!-- post Location -->
<p><label for="Location">Location:</label><br />
<p><?php wp_dropdown_categories( \'show_option_none=Category&tab_index=4&taxonomy=location\' ); ?></p>
<!-- post Services -->
<p><label for="Services">Services:</label><br />
<p><?php wp_dropdown_categories( \'show_option_none=Category&tab_index=4&taxonomy=services_c\' ); ?></p>
<!-- post Content -->
<p><label for="description">Content</label><br />
<textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea>
</p>
<!-- post tags -->
<p><label for="post_tags">Tags:</label>
<input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( \'new-post\' ); ?>
</form>
</div>