• Resolved cicolino

    (@cicolino)


    Hello.

    Im building the listing site where each user can submit one listing with ACF EX Form. Everything is working fine, submiting and editing (if edit form is on submited post). How can I make that user can edit with form from fronted dashboard (extra page)?

    thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    You can pass a custom data to a form such as the Post ID to update, and then retrieve it in your Form UI using the {form:my_data} template tag.

    This will allow you to create a page called /update-list for example, which will display a form that will update a specific post, with the post id that you programmatically set.

    You’ll find a guide explaining this process in the “Passing Data to a Form” guide here.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter cicolino

    (@cicolino)

    Thanks for your answer.

    Please, can you give me a code example for my case.
    User can submit only one post, I get this function with this code and is working well

    add_filter('acfe/form/load/form=band_submit', 'my_form_settings', 10, 2);
    function my_form_settings($form, $post_id){
    
        // get current user
        $user = wp_get_current_user();
        
        // check for current user role CUSTOMER
        if(in_array('um_band-author', (array) $user->roles)){
            
            // get posts of the current user (by post_author)
            $get_user_posts = get_posts(array(
            'post_type'      => 'band',
            'posts_per_page' => -1,
            'author'         => get_current_user_id()
        ));
    
            // CUSTOMER has at least 1 post, hide the form
            if(count($get_user_posts) > 0){
                
                // hide the form
                return false;
    		
    		}
        }
    
        // display form
        return $form;
        
    }

    I’m trying to make edit from extra page ( /edit-post ) but without success
    My form for editing is band_edit

    thanks

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello!

    If you want to use a generic page such as /edit-post that display a form which edit a specific post from the current logged user seeing the page, you’ll have to pass post id you want that form update as explained in the Passing Data to a Form tutorial.

    It can be represented like this:

    add_filter('acfe/form/load/form=edit_page', 'my_form_edit_page', 10, 2);
    function my_form_edit_page($form, $post_id){
        
        // get current user id
        $user_id = get_current_user_id();
        
        // no user id, hide the form
        if(!$user_id){
            return false;
        }
        
        // get the "band" post where the current user is author
        $get_user_posts = get_posts(array(
            'post_type'      => 'band',
            'posts_per_page' => 1,
            'author'         => $user_id
        ));
        
        // no band post found, hide the form
        if(empty($get_user_posts)){
            return false;
        }
        
        // get the first post id found in the query results
        $post_id_to_edit = $get_user_posts[0];
        
        // pass 'post_to_edit' to the form
        // this can be retrieved in the Form UI
        // using {form:post_tot_edit} as "Target" or "Load source" in the Post Action settings
        $form['post_to_edit'] = $post_id_to_edit;
        
        // return form
        return $form;
        
    }

    You can then use the {form:post_to_edit} Template Tag in the Form UI, as Post Action “Target” and “Load Source” settings for example.

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Edit custom post from User Dashboard’ is closed to new replies.