Home Forums General Issues accessing data durring save action from acf_form


accessing data durring save action from acf_form

  • Hello,

    I want to build a function like the functions.php example here.

    add_action('acf/save_post', 'my_save_post');
    function my_save_post( $post_id ) {
      error_log('my_save_post called');
      // bail early if not a contact_form post
      if( get_post_type($post_id) !== 'workstuff' ) {return;}
      // bail early if editing in admin
      if( is_admin() ) {return;}
      // get custom fields (field group exists for content_form)
      $name = get_field('name', $post_id);
      $email = '[email protected]';
      $photo = get_field('photo', $post_id);
      $description = get_field('description', $post_id);
      error_log('$id: '. $post_id);
      error_log('$description: ' . $description);
      error_log('$photo: ' . $photo['url']);
      error_log('$email: ' . $email);
      error_log('$name: ' . $name);

    In my error log I see that the function is being called, I am gettin the $post_id and the statically set ’email’ variable is being printed out but the data from the fields is not being printed out.

    The name and descriptions fields are text and textarea. The photo field is an image returning an object.

    I might just be missing something obvious. Thanks for the help.

    btw the post is getting created as expected with the fields and photo attached.

  • try setting the priority of your action to 20

    add_action('acf/save_post', 'my_save_post', 20);
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘accessing data durring save action from acf_form’ is closed to new replies.