如果我在选择类别后提交帖子,帖子不会被提交,相反,它会将我带到我选择的类别页面。但是,如果我删除字段集“category”并填写表单,它就可以正常工作。有什么解决办法吗?
PHP就是这样。
<?php
if( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == "new_post") {
if (isset ($_POST[\'description\'])) {
$description = $_POST[\'description\'];
} else {
echo \'Please enter some notes\';
}
$tags = $_POST[\'post_tags\'];
$category = array(intval($_POST[\'cat\']));
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
\'post_title\' => $title,
\'post_content\' => $description,
\'post_category\' => $category,
\'tags_input\' => array($tags),
\'post_status\' => \'publish\',
\'post_type\' => \'post\', //
);
$pid = wp_insert_post($new_post);
wp_set_post_tags($pid, $_POST[\'post_tags\']);
wp_set_post_categories($pid, $_POST[\'cat\'] );
$link = get_permalink( $pid );
wp_redirect( $link );
}
do_action(\'wp_insert_post\', \'wp_insert_post\');
?>
还有html。。
<div class="wpcf7" style="margin-top: 100px;">
<form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
<!-- post name -->
<fieldset name="name">
<label for="title">Name</label>
<input type="text" id="title" value="" tabindex="5" name="title" />
</fieldset>
<!-- post Category -->
<fieldset class="category">
<label for="cat">Type:</label>
</fieldset>
<!-- post Content -->
<fieldset class="content">
<label for="description">Description and Notes:</label>
<textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
</fieldset>
<!-- post tags -->
<fieldset class="tags">
<label for="post_tags">Additional Keywords (comma separated):</label>
<input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
</fieldset>
<fieldset class="submit">
<input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />
</fieldset>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( \'new-post\' ); ?>
</form>
</div>