DEV Community


Create a Front-end form with Advanced Custom Field(ACF)

Keramot UL Islam
WordPress Enthusiast. Loves PHP, and JavaScript.
Originally published at Medium on ・1 min read

acf front-end form

Yes, you heard right. We can create a front-end form with ACF. Let’s say, we have some users and we want them to create posts from a front-end form and those posts will be saved as Draft on the admin panel for Admin approval.

It sound’s tough but ACF makes it super easy for us. acf_form() will do all the hard works for us.

$agrs = array(
    'post_id'  => 'new_post',
    'new_post' => array(
        'post_type'   => 'post',
        'post_status' => 'draft'
    'post_title'      => true,
    'post_content'    => true,
    'submit_value'    => esc_html__( 'Add Post', 'text_domail' ),
    'updated_message' => esc_html__( 'Post Saved.', 'text_domail' )

acf_form( $agrs );

This function is going to create a front-end form for the user's input but it’ll not save those data. acf_form_head() is the function which going to save those data. It is very important to add this hook before get_header(). Yeah, it sounds annoying but that’s how it works.

Discussion (0)