title: Edit post from frontend with update
body: <p>So, I have the following code to allow front-end edit for wordpress taken from here : <a href="https://wordpress.stackexchange.com/questions/9912/front-end-post-editing-using-a-form">https://wordpress.stackexchange.com/questions/9912/front-end-post-editing-using-a-form</a></p>
  
  <pre><code> &lt;?php
      if ( 'POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; ! empty($_POST['post_id']) &amp;&amp; ! empty($_POST['post_title']) &amp;&amp; isset($_POST['update_post_nonce']) &amp;&amp; isset($_POST['postcontent']) )
      {
      $post_id   = $_POST['post_id'];
      $post_type = get_post_type($post_id);
      $capability = ( 'page' == $post_type ) ? 'edit_page' : 'edit_post';
      if ( current_user_can($capability, $post_id) &amp;&amp; wp_verify_nonce( $_POST['update_post_nonce'], 'update_post_'. $post_id ) )
      {
          $post = array(
          'ID'             =&gt; esc_sql($post_id),
          'post_content'   =&gt; esc_sql($_POST['postcontent']),
          'post_title'     =&gt; esc_sql($_POST['post_title'])
      );
          wp_update_post($post);
  
          if ( isset($_POST['edit_test']) ) update_post_meta($post_id, 'edit_test', esc_sql($_POST['edit_test']) );
          if ( isset($_POST['edit_test2']) ) update_post_meta($post_id, 'edit_test2', esc_sql($_POST['edit_test2']) );
                          }
                          else
                          {
                              wp_die("You can't do that");
                          }
                      }
                  ?&gt;
  
      &lt;form class="royal_page" role="form" method="post"&gt;                 
          &lt;input type="hidden" name="post_id" value="&lt;?php the_ID(); ?&gt;" /&gt;
          &lt;?php wp_nonce_field( 'update_post_'. get_the_ID(), 'update_post_nonce' ); ?&gt;
  
          &lt;p&gt;&lt;label for="post_title"&gt;Title&lt;/label&gt;
          &lt;input type="text" id="post_title" name="post_title" value="&lt;?php echo $post-&gt;post_title; ?&gt;" /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;?php wp_editor( $post-&gt;post_content, 'postcontent' ); ?&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="post_title"&gt;Test&lt;/label&gt;
          &lt;?php $value = get_post_meta(get_the_ID(), 'edit_test', true); ?&gt;
          &lt;input type="text" id="edit_test" name="edit_test" value="&lt;?php echo $value; ?&gt;" /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="post_title"&gt;Test 2&lt;/label&gt;
          &lt;?php $value = get_post_meta(get_the_ID(), 'edit_test2', true); ?&gt;
          &lt;input type="text" id="edit_test2" name="edit_test2" value="&lt;?php echo $value; ?&gt;" /&gt;&lt;/p&gt;
  
      &lt;input type="submit" id="submit" value="Update" /&gt;           
     &lt;/form&gt;      
  </code></pre>
  
  <p>So, editing the post itself works just fine. Once the edit is submitted and then page is refreshed.</p>
  
  <p>I see the change that has been made after the refresh. However the edit form no longer contains the contents and I have to refresh the page again in order to see it (See below for image).</p>
  
  <p><a href="https://i.stack.imgur.com/uZUL1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uZUL1.png" alt="enter image description here"></a></p>
  
  <p>Does anyone know why it might be doing that and if there any solution to how to fix it?</p>
  
  <p>Thanks!</p>