Advanced Custom Fields
How to save fields on custom front-end form? (3 posts)

  1. sp880111
    Posted 2 years ago #

    I would like to style my own front-end form (that creates a new post) and save the field inputs as ACF fields (so not using acf_form()).

    What's the easiest/cleanest way to do so?

    The only solution that comes to my mind after reading the Doc is:

    1. Create <input> fields
    2. Upon submit grab every field with $_POST[..]
    3. Look up the field_keys (e.g. field_424244ec4cds03) and run wp_update_postmeta to create every meta entry manually
    4. Is that the way to go?

      I was wondering whether there might be a chance to hook into somewhere and do something like $_POST['fields']['field_key']=my_value. This way I would change the value before it is inserted into the database by ACF (no need to do the database insertion by myself..).

      Any ideas/help greatly appreciated!


  2. Michael Mann
    Posted 2 years ago #

    I see no reason why you cannot use $_POST['fields']['field_key']. ACF's acf_forms() uses this inside the theme's functions.php file. Perhaps you could use this somehow:

    function my_pre_save_post( $post_id )
        // check if this is to be a new post
        if( $post_id != 'new' )
            return $post_id;
        // Create a new post
        $post = array(
            'post_status'  => 'publish' ,
            'post_title'  => $_POST['fields']['field_name'] ,
            'post_type'  => 'posts' ,
        // insert the post
        $post_id = wp_insert_post( $post ); 
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
        // return the new ID
        return $post_id;
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
  3. shri80
    Posted 2 years ago #


    Can u pls explain how to put ACF custom Field in following
    $post = array(
    'post_status' => 'publish' ,
    'post_title' => $_POST['fields']['field_name'] ,
    'post_type' => 'posts' ,

    I dont wish to use acf_form because there is come JS issue with my theme which dont allow me to browser image

    So it will be better if u show me how to add a ACF text field and ACF image filed in $Post

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic