acf/validate_save_post vs acf/save_post

Viewed 220

I want to validate a post before to submit.
Is there any differences?

add_action('acf/validate_save_post', 'my_acf_validate_save_post');
function my_acf_validate_save_post() {
  // Do validate.
}
1 Answers

Both actions are ajaxed before submit.

acf/validate_save_post

  • No args.
  • Cannot retrieve old post data.
  • Get new post data from $_POST.
  • You can set errors by using acf_add_validation_error. You must know html input name of ACF field. eg) acf_add_validation_error( 'acf[field_628ca71315e3d]', 'Please check this input to proceed' );

acf/save_post

  • 1 arg: $post_id
  • Get old ACF field values from get_fields( $post_id ). eg) [ 'price' => 1000 ]
  • Get new ACF field values from $_POST with a part of html input names. eg) [ 'field_628ca71315e3d' => 2000 ]
  • Cannot set errors.
Related