Support

Account

Home Forums General Issues ACF Fields not saving when post/event is submitted

Solving

ACF Fields not saving when post/event is submitted

  • I am having an issue saving ACF Fields to an Events Calendar Community Event submission.

    I’ve added

    add_action( 'init', 'add_acf_form_head_init', 10 );
    function add_acf_form_head_init(){
    	acf_form_head();
    }

    to the functions.php

    and within the overwritten template for that event page I added these

    			<?php
        $settings = array(
          'field_groups' => array('group_626b2ac8a9307'),
          'form' => false
        );
        acf_form($settings);
      ?>
    add_action( 'get_header', 'call_acf_form_head', 1 );
    function call_acf_form_head() {
       acf_form_head();
    }

    I’ve created two videos one showing with the first function being called ‘init’ hook of wordpress in functions.php. in the video you will see the Post “Updated” but no form submission or saving. https://drive.google.com/file/d/1AZFsFHtlpbLA7yLchc3vZaJMH2BSQ_Oi/view?usp=share_link

    And in this video, I disabled the function in function.php. The event gets submitted, but the ACF Fields do not get saved.
    https://drive.google.com/file/d/101lVRupiDuNXN81Lok3RYtUZ-2xApbg9/view?usp=share_link

    Am I missing something? I’ve also enabled debugging to see if it gets printed to my debugger or json, but nothing happens to no avail

    Send help

  • Are you creating new posts or updating existing posts?

    If you are updating existing posts then you need to supply the post ID of the current post using the “post_id” argument for acf_form().

  • creating a new post/new event

  • You are likely going to need to talk to someone that knows how the even plugin works. ACF saves fields on the WP save_post hook do_action( 'save_post', $post_id, $post, $update ); and depends on the $post_id to tell it where to save the fields.

    There are some possibilities.

    The other plugin is not created posts like is normal and this hook is never fired.

    The events calendar uses serveral post types and it’s possible that the hook is fired more than once or for some other reason the post_id that ACF is getting is not the actually post that is being created or that you think it is.

    Are you sure that the fields are not saved anywhere, look in the DB and search the meta key for the field name to see if it’s saved but for the wrong post.

  • I’ll try to add the save post function. is there a way to only target from these types of post types?

  • I don’t think that will help you unless you are sure that the other plugin is not using wp_insert_post() to add the event post.

  • I wont know until I know lol

  • The reason that I say this is that one thing I know about the events calendar is that they use multiple post types and you may not be aware that there are multiple post types. These post types have a complicated parent/child relationship that is not apparent in the admin.

    If that plugin is triggering the WP save_post action, but on some other post type then ACF will save the data to the first post added that triggers the action. Then it will not save that values again. So adding something to trigger that action will do nothing at all if it has already been triggered.

    What I would do is

    
    // high priority to happen after everything else
    add_action('save_post', 'my_save_post_check_function', 999, 3);
    my_save_post_check_function($post_id, $post, $update) {
      echo 'DID save_post<br />'
      if (did_action('acf/save_post)) {
        echo 'DID acf/save_post on <br />';
        echo '<pre>'; print_r($post);
      }
      die;
    }
    

    What that will do is tell you 3 things,
    1) that save_post was triggered
    2) that ACF has saved the values
    3) what post ACF saved the values against

    then execution will stop.

  • Sweet! I will try it out! would I be able to output this to a debugger as well?

  • I’m not sure what you mean by output to a debugger.

    Instead of “die;’ your you could do something like error_log()

  • So I tried the function you created and it completely blanks the page

  • Sp that means that save+post was triggered but that acf did not save anything. Are you sure it’s submitted?

    Going back to your OP.

    Where did you put the acf_form() call?

    Do the acf fields appear between the opening and closing <form> tags for the event calendar form?

  • I actually didn’t even do anything I just navigated to the page and that function triggered.

  • and to answer your second question, I put the fields in between the <form> tags

  • Just visiting the page should not cause the save_post action to fire. No idea how to help you there.

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

You must be logged in to reply to this topic.