Display ACF Frontend Form for specific Fields Group

Coding

Filed Under: Code Snippets, WordPress


Advanced Custom fields is a most popular plugin used for add custom fields in WordPress based websites. Most of the times, developers only interact with ACF within admin dashboard which needs no coding knowledge.

In some scenarios, you need frontend users to add/edit posts. In that case you’ll need to include frontend form with advanced custom fields.

I will share code snippet to display ACF frontend form for specific fields group.

Advertisement

Lets say, we have created a field group “Extra Listing Information” for custom post type ‘listing“, the code we need to use to display its frontend from is below.

Display ACF Frontend Form for Specific Fields Group

First of all, you need to call following function after get_header(); in the template file where you want to display ACF Frontend Form.

acf_form_head();

It will register the necessary assets (CSS/JS), process the saved data, and redirect the url.

Then you need to call a following function where you want to display acf frontend form.

acf_form();

This function accepts an array or settings to customize the form in many ways.

The sample settings to display acf frontend form are:

$settings = array(
'post_id' => 10,
'new_post' => false, //true if you are using form to add new post
'field_groups' => apply_filters( 'acf/field_group/get_fields', $fields, 'id_of_fields_group' ),
);

So, you need to pass the $settings array to the acf_form function.

acf_form( $settings );

You can find all the settings that you can use here.

Conclusion

I hope the above tutorial will help you to display acf frontend form. If you find any difficulty, feel free to leave a comment below, I will get back to you as soon as I could.

Also Read:


Tags: , ,



Leave a Reply

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