If I submit the post after choosing a category the post doesnt get submitted and instead it takes me to the category page i have selected.However if i delete the fieldset "category" and fill the form it works fine. Any solution to this?
The PHP is this.
<?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');
?>
And the 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>