• Resolved wnerd

    (@wnerd)


    Hi,

    First I’d like to say, great job building ACF Extended. It’s an amazing plugin adding lots of extra features!

    About my question:

    I am currently trying to set up a form that creates both a user account and adds a custom post in 1 take.

    This works well, but I notice the author of that post is always “admin”, whereas I’d like it to be the user from the form.

    Is this possible?

    Currently my actions are as followed:

    create user, with an email and password field
    create post, with my cpt and post and author is “current user”

    I tried adding a step between those, by logging the user in, but that didn’t work either.

    I also looked at the cheatsheet and tried {user}.

    Thanks so much for your time!

    Regards,

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I’m glad to hear that you enjoy ACF Extended 🙂

    The Template Tag you’re looking for is {action:user:ID} (See documentation). If you set that Template Tag in the Post Action “Author” field, it will tell the form to use the previous “User Action” ID as the author of the post.

    Additionally, if you want to automatically log the user on form submission, you can use the following code:

    add_action('acfe/form/submit/user/form=my-form', 'my_form_submit', 10, 5);
    function my_form_submit($user_id, $type, $args, $form, $action){
        
        // log user after user registration
        wp_clear_auth_cookie();
        wp_set_current_user($user_id);
        wp_set_auth_cookie($user_id);
        
    }

    Note that there will be a setting allowing you to do that from the From UI in a future version, but in the meantime, you can use this code.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter wnerd

    (@wnerd)

    Thank you so much, that worked!

    Keep up the great work!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Awesome!

    Thanks for the nice review BTW 🙂

    Have a nice day!

    Regards.

    Thread Starter wnerd

    (@wnerd)

    Hi Konrad,

    Thanks again for your help yesterday.

    Hope you don’t mind me asking, but if you see some time you might know the answer to this question:

    I have create 2 post types, 1 is a project and 1 is a comment that the current user posts.

    I was able to link them via acf via the relationship fields and they are displayed on the front-end single page.

    When I link them manually in the wp backend it works, but I’d like to make it work with the acf extended forms so that it will post the comment directly on the project page.

    How do I accomplish this?

    I set up 1 form action posting the comment (which works) but how do I link it to the project I am on so the comment is displayed there?

    I tried a second action to update the project post type with the comment, but I don’t know how to move forward.

    Thanks!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    First, I would recommend to use the Post Object field with a single select. So the value saved in the database will be a single Post ID, instead of an array of Post IDs (that’s how the Relationship field save values). Having a single ID in the database is easier to query posts with WP_Query.

    Regarding your question about the “Comment Form” on a Post, you can simply update your Post Object (relationship) using the acfe/form/submit/post hook if you’re using a Post Action to create your comment (See documentation).

    In that hook you can use update_field() (See documentation) to update your relationship with the current post id (where the Comment Form is displayed). usage example:

    add_action('acfe/form/submit/post/form=my-form', 'my_form_submit', 10, 5);
    function my_form_submit($post_id, $type, $args, $form, $action){
    
        // $post_id is the newly created "comment" post id
        
        // retrieve current post id (where the form is displayed)
        $current_post_id = $form['post_id'];
        
        // update relationship with current post id
        update_field('my_relationship', $current_post_id, $post_id);
        
    }

    If you need to pass other custom data to your “Comment Form” to use it in the UI or a hook, I owuld recommend to check the guide: Passing Data to a Form.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter wnerd

    (@wnerd)

    Hi,

    Thank you that did it!

    Kind regards,

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Awesome!

    Have a nice day!

    Regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Create account and post in 1 form’ is closed to new replies.