Edit form for custom loop post

So, I have a custom loop post.

On the page, I have 10 posts as below:

Read More
<?php   
$args = array( 
    'post_type' => 'mail',
    'paged'=>$paged,
    'posts_per_page' => 10,
    'mail_cat' => '',
    'orderby' => 'date',
    'order' => 'DESC',      
    );      
$loop = new WP_Query( $args );  
while ( $loop->have_posts() ) : $loop->the_post(); 
?>

Each post gets title, content and price based on the data-mail_id as below:

<div data-mail_id="' . esc_attr( $mail->id ) . '">
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php echo $mail->get_price_html(); ?>
</div>

Now, how can I add an edit form (<form>) to edit the post contents?

I am guessing I need following:

  1. Get the <form> with the targeted post-mail_id data such as title.
  2. Change the contents of the post
  3. Submit the change which will update the data for that specific post-mail_id.

What do you guys think?

EDIT 1:

Well, I am not sure if this is correct, but it is a start :p

<form role="form" method="post">                    
    <?php wp_nonce_field( 'update_post_'. get_the_ID(), 'update_post_nonce' ); ?>                           
    <div id="title_change">                                         
        <input type="text" id="post_title" name="post_title" value="<?php echo $post->post_title; ?>"></input>              
        <input  type="submit" name="update" type="submit" ></input>
    </div>
</form>

So, now what? lol

So, I can show the original title in the input field.
I am not sure how the change can be submitted and be updated.

Related posts