Support » Plugins » Hacks » Problem Updating Post With wp_insert_post

  • I am trying to change the title and content of a post, while leaving its slug and ID unchanged. Simultaneously, I am trying to save options for use in the updated post, or possibly save the modifications as metadata.

    I don’t understand what I am doing, and it doesn’t save or overwrite the existing post.

    Any suggestions on how to find and correct my error?

    Here is my code …

    // Data to insert into post
      global $user_ID;
      $offer_3_post = array(
    // Identify the post that will be overwritten
    'ID' => $target_3_postid ,
    'post_category'  => array($target_3_cat_id),
    // Fille the new array with standard information
    'post_status' => 'publish',
    'post_date' => $target_3_post_date,
    'post_author' => $user_ID,
    'post_name' => $target_3_post_slug,
    'post_type' => 'post',
    'comment_status' => 'closed',
    'ping_status' => 'closed',
    // Fill the new array from the old
    'post_title' => $source_3_title,
    'post_content' => $source_3_content,
    'post_excerpt' => $source_3_excerpt,
    'to_ping' => $source_3_toping,
    'pinged' => $source_3_didping,
    'post_content_filtered' => $source_3_filteredcontent,
    'post_parent' => $source_3_parent,
    'guid' => $source_3_guid,
    'post_mime_type' => $source_3_mimetype
      <form action="" name ="offer_3_options" method="post">
      <b>Edit your offer description here.  Describe what you are willing to do as part of this offer. <br />(Your offer is limited to 250 characters.):</b>
      <br /><br />
      <textarea name="offer_3_t1" rows="5" cols="90" maxlength="250" ><?php echo get_option(offer_3_t1); ?></textarea>:
      <br /><br />
      <b>Enter the price or discount for your offer. <br />(Space is limited to 7 characters.):</b>
      <br />
      <input type="text" name="offer_3_n1" size="10" maxlength="7" value="<?php echo get_option(offer_3_n1); ?>">
      <br /><br />
      <b>Enter or edit the terms of any guarantee that you are offering with this special offer.  <br />(Your guarantee is limited to 150 characters.):</b>
      <br /><br />
      <textarea name="offer_3_t2" rows="5" cols="90" maxlength="150" ><?php echo get_option(offer_3_t2); ?></textarea>:<br />
      <br /><br />
      <b>Once you've made all your changes, click the button below to save your changes and then take a look at your home page and the offers page on your site to verify your edits and admire your work.</b>
      <br /><br />
      <!-- These input fields and the submit button are copied from another page that actually "worked." -->
    	<input type="hidden" name="prev_offer_3" value="<?php $target_3_post_slug ?>" />
    	<input type="hidden" name="action" value="update" />
    	<input type="hidden" name="offer_3_options" value="offer_3_t1, offer_3_n1, offer_3_t2" />
    	<input type="submit" name="offer_3_options" value="Save Offer #3 Changes" />
      if(isset($_POST['offer_3_options'])) {
      // Update the post into the database
      wp_insert_post( $offer_3_post );

  • The topic ‘Problem Updating Post With wp_insert_post’ is closed to new replies.