custom post types – Metabox update with submit button in front end


I wish to permit user to accept documents.
I created cpt name “direction” documents. I display all this post in a loop.
I created a metabox called “List user accept document” in my cpt.

I whish when user click on “accept” button in front-end, this will update the metabox and add his name in the backend and keep the status ‘”accepted” when he is back on the website.

My metabox :

function files_direction_accepted() {
        'List user accept document',
add_action( 'add_meta_boxes', 'files_direction_accepted' );
function users_direction_accepted() {
    echo 'something';

My loop :


        $loop = new WP_Query( 
                'post_type' => 'documents-direction', // cpt name
                'posts_per_page' => '-1' ) 

        while ( $loop->have_posts() ) : $loop->the_post(); 
            $postid = get_the_ID();
            $post_to_edit = get_post($postid); 
            $pdf = get_field('pdf', $postid); // get ACF field

                <div id="postbox">
                    <form id="new_post" name="new_post" method="post" action="">
                        <p><a href="<?php echo $pdf ?>"><?php echo the_title() ?></a></p> 
                        <p><input type="submit" value="Accepter" tabindex="6" id="submit" name="submit" /></p>
                        <input type="hidden" name="action" value="f_edit_post" />
                        <input type="hidden" name="pid" value="<?php echo $post_to_edit->ID; ?>" />
                        <input type="hidden" name="users_direction_accepted" value="" />
                        <?php wp_nonce_field( 'new-post' ); ?>
        endwhile ;


        if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "f_edit_post" && isset($_POST['pid'])) {  
            $post_to_edit = get_post((int)$_POST['pid']); 
            $pid = wp_update_post($post_to_edit); 


display list user
How to edit the code to do that ?

Thanks for your help

nono 2 months 2021-12-01T06:12:24-05:00 0 Answers 0 views 0

Leave an answer