Home Forums ACF PRO acf/save_post error


acf/save_post error

  • The following code worked before I installed the latest ACF Pro. On frontend form submission, the action reverse geocodes a Google Map field and splits it up by Address, City, State, and saves to a hidden area shown only to admins in a custom post type. These hidden fields do not show on the frontend form itself.

    As noted, it worked before the update to 5.6. I’ve dumped the data for $loc_data and the array is populated with the correct info. I’ve also verified the fieldIDs for each field.

    Any thoughts on what might have changed in the last few versions or if there’s a new/better way to do this?

    add_action('acf/save_post', 'acf_location_data', 1);
    function acf_location_data( $post_id ) {
    	//	Check if this is submitting from front-end and contains lat field
    	if ($_POST['acf']['field_56aa34b90aee5']['lat']){
    		$loc_data = reverse_geocoding($_POST['acf']); // Send all data to reverse geocode function
    		$_POST['acf']['field_56aa34b90aee5'] = array(); // Clean Array
    		$_POST['acf']['field_56aa34b90aee5'] = $loc_data;
    		 // insert all the data calculated in the function above for address
    		$_POST['acf']['field_56aa7bfc5329f'] = $loc_data['theAddress'];  // store readable street number and address
    		$_POST['acf']['field_56aa59411b6a5'] = $loc_data['city'];  // store city field_56aa59411b6a5
    		$_POST['acf']['field_56aa7bf55329e'] = $loc_data['state'];  // store state
    		$_POST['acf']['field_56aa7c02532a0'] = $loc_data['zip'];  // store state
  • do_action( 'acf/save_post' , $post_id ); doesn’t work too with ACF PRO 5.6.0, it was working fine with 5.5.14

  • @kaust it appears that the way acf/save_post works, or more specifically, the ACF action function works, has been altered. The hook now passes the values to be saved and works off of the passed array rather than the $_POST array. What this means is that the alterations that your making to this array are done after ACF had retrieved the values.

    What this means is that you’ll need to run your function ACF gets the values from $_POST. I’m not really sure what the best hook for this would be, but I also need to investigate this because I have a plugin that relies on something similar to what you’re doing. I’m thinking that acf/init might be the way to go. I’ll let you know if I find anything else out.

    you are running into this issue because you are not passing the $_POST[‘acf’] array when calling.

  • @kaust yes, you need to change from acf/save_post to acf/init, in your case it could also be init, basically anywhere that it is save to start messing with the $_POST array.

    Also in your case, since your not using $post_id you can just remove that argument. If you needed that value then you’d have to figure out what the current post ID value is for yourself.

  • It looks like the next update should revert these changes.

  • Hi guys

    Elliot here – ACF dev.

    Sorry about the recent ‘acf/save_post’ and $_POST[‘acf’] issues.
    I’m aware of the problems and have fixed the (ad re-uploaded the plugin files).

    Please be sure to checkout the known issues guide here:

    Please re-download the plugin files, or await 5.6.1


  • Thanks E, for letting us know. In my case I think I’ll probably leave my changes to do this on acf/init because of what it is I’m doing because it ensures more easily, that the changes happen before any acf/save_post actions that other plugin and theme authors might add.

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

You must be logged in to reply to this topic.