Home Forums Backend Issues (wp-admin) Saving hidden fields in a custom field


Saving hidden fields in a custom field

  • I’m really struggling with this and I hope you can help.

    What I’m trying to do is add data to hidden fields and then save it to the database. The fields are from a pre-existing theme and I have to use the post meta key that already exists in the database.

    I can get the fields to load the existing data, but I can’t figure out how to save the data when the post is updated.

    I made a custom meta box that works, but I want this to be a custom ACF field. I have everything working except saving the hidden fields.

    Jason WItt

  • Hi

    after u create front end form pls put following function in your function.php, add the required filed to post

    add_filter(‘acf/pre_save_post’ , ‘my_pre_save_post’ );
    function my_pre_save_post( $post_id ) {
    // check if this is to be a new post
    if( $post_id != ‘new’ ) {
    return $post_id;

    $field = $_POST[‘fields’];
    $post_title = $_POST[‘fullname’];
    $post_content = $field[‘edit_test2’];
    $post = array(
    ‘post_status’ => ‘draft’ ,
    ‘post_title’ => $post_title,
    ‘post_content’ => $post_content,
    ‘post_type’ => ‘page’


    add_post_meta($newpost_id,’FullName’, $fullname);
    add_post_meta($newpost_id, ‘address’, $address);

    You can also refer following article

  • Thanks for the reply, but this isn’t what I meant. Maybe I didn’t explain it too good. The problem I was having is for a custom field, not a front-end form.

    I figured out a solution on my own. I made added a save_post function, like you would if you made a custom meta box to save the hidden fields. I just called that action from the constructor.

    It seems like maybe one of the built in functions from the custom field template would have been better to use, but I could figure out which one, if any I should be using.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Saving hidden fields in a custom field’ is closed to new replies.