Support

Account

Home Forums Feedback ACF/save_post question Reply To: ACF/save_post question

  • Odd that your previous function didn’t work..

    I tried thinking outside of what you’ve done so far and perhaps this would work? It’d be a lot simpler altho maybe not as good performance-wise.. I don’t think it matters tho since it’s in the admin and it’s not that big off a loss that anyone would notice.

    
    function my_acf_save_post( $post_id )
    {
    
    	//The fields have already been saved to the database so lets retrieve them
    	$event_start = get_field('field_5217ac66687dc', $post_id);
    	$event_end = get_field('field_524b4ca5ff418', $post_id);
    	
    	//check if event_end exists, if it was empty it should not. You can make sure of this in database.. perhaps it has to be changed to $event_end == ''
    	if(!$event_end){
    		//update event_end. Parameters are field key of event_end, event_start value and the post id. 
    		update_field('field_524b4ca5ff418', $event_start, $post_id);
    	}
    	
    }
     
    // run AFTER ACF saves the $_POST['fields'] data to database
    add_action('acf/save_post', 'my_acf_save_post', 20);