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.

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']));

$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" />

        <!-- post Category -->
 <fieldset class="category">
    <label for="cat">Type:</label>

        <!-- post Content -->
        <fieldset class="content">
            <label for="description">Description and Notes:</label>
            <textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>

        <!-- 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 class="submit">
            <input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />

        <input type="hidden" name="action" value="new_post" />
        <?php wp_nonce_field( 'new-post' ); ?>

an echo before inserting content, are you sure ?

Possibly sending headers, blocks insert POST request and set pid to empty value.

if (isset ($_POST['description'])) {
     $description = $_POST['description'];
} else {
    echo 'Please enter some notes';
  • i was gonna get to validation after the category issue was over... – Megh Gandhi Jul 29 '15 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.