How to show ACF user forms on the front-end

How to show ACF user forms on the front-end

If you love ACF Pro the way we do then at some point you’ll want to leverage it for user field data. And then the question becomes, how can I show some of these fields to my users so they can update their own data?

The answer is of course acf_form(). The trick is that you’ll need to use the ‘post_id’ setting, passed as part of your settings array to acf_form( $settings ). But wait, there is no post ID right? In ACF sometimes, and you’ll see this also with get_field(), the “post_id” for other content types is created by prefixing the content type. In this case we need to pass ‘post_id’ as ‘user_USERID’. For example if the current user has ID 84, we need to pass ‘user_84’. Simple enough right?

In the example below we get the current user id using the WordPress function get_current_user_id(). You can use other functions from WordPress as well, you might load the $user object and then get the ID from it for instance. Now in the event you don’t want to show the current user form, instead you want to show a specific user form, perhaps because you’re managing other users or something, then the same approach applies. You just identify the user ID you want to specify and then pass it to acf_form() as ‘post_id’ using the ‘user_’ prefix.

acf_form_head();
    $settings = [
      'post_id' => 'user_' . get_current_user_id(),
      ... other settings here ...
    ];
 acf_form( $settings );

Leave a Reply

Your email address will not be published. Required fields are marked *

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

admin

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

admin