Home › Forums › Bug Reports › ACF PRO: Possible bug in acf/save_post
Prior to upgrading ACF4 to ACF PRO with developer license, I had a function that was executed on acf/save_post with priority 1 to be able to compare previous and new value of a specific field.
After upgrading to ACF PRO, acf/save_post with priority 1 (before fields are saved) doesn’t seem to work any different than priority 10 (after fields are saved).
When running the function, I get an error that says $_POST[‘fields’] is not defined.
Is it possible that this is a bug, or am i missing something?
I’m using the action inside a plugin like so:
add_action('acf/save_post', array($this, 'compare_field_values'), 1);
Is someone looking into this? It was reported 1,5 month ago and keeps me from upgrading several sites from ACF 4 to 5.
Second that! I’m working on a new site that using v5 and now I’m stuck cause of this bug.
What I’m trying to do is compare the old and new values of a field when a post is saved using acf/save_post with priority 1, which is supposed to run before ACF saves the $_POST[‘acf’] data.
The field values always comes out equal, which they are not supposed to do, right?
Example data:
field_abc123 old value: Title One
field_abc123 new value: Title Two
Example code:
function compare_field_values($post_id) {
// Print old and new field values
var_dump(get_field('field_abc123', $post_id);
var_dump($_POST['acf']['field_abc123']);
// Exit to be able to debug the field values
exit();
}
add_action('acf/save_post', array($this, 'compare_field_values'), 1);
So, anyone have any idea on how to solve this? Or is there a bug in ACF when setting the priority to 1 on acf/save_post?
I can confirm this bug with the 5/PRO (5.08) version as well.
Any thoughts?
It’s very annoying since it keeps me from upgrading several client’s sites to ACF PRO. I will try to get Elliot Condon’s attention on this problem.
Hi guys.
Sorry for the late reply.
It is no longer possible to hook into the ‘acf/save_post’ action (with a priority of less than 10) before ACF has saved it’s data.
Instead, you can hook into the validation which is always run before saving. This can be done on a field by field level with the filter acf/validate_field
(http://www.advancedcustomfields.com/resources/acf-validate_value/) or the action 'acf/validate_save_post'
(no docs yet, but found in core/input.php on line 430)
Also, $_POST['fields']
has changed to a safer $_POST['acf']
Sorry for the inconvenience, and please be sure to let me know if the logic you are trying to accomplish is not possible with these alternatives.
Hello Elliot
The suggested validate logic is not solving the issue for me unfortunately. Any chance of bringing back the save_post logic or any specific reason you’ve removed it? I was generating a stylesheet upon Options Save with the following code:
function generate_stylesheet() {
// Generate stylesheet
}
// After theme options save
add_action('acf/save_post', 'generate_stylesheet', 20);
.. so it was dependent on the action to run AFTER the Save as all the new values needs to be fully saved in db before it triggers the stylesheet creation.
If acf/save_post after action is gone forever, what would be your recommendation for a comparable solution in my case?
Thanks!
Any updates on this? I basically just need a function to run after an option page has been saved.. Should be possible right?
Gesen, did you get it working somehow?
Haven’t hade the time to try it out until now.
Just to back up a bit: I’m trying to compare the new value of a field to its previous value. To be able to do this I need to know the field name/key, the previous value, and the new value. To get the previous value, I need to know the post ID of the post that’s being saved.
When trying out the acf/validate_value/name=[field_name]
action, I can’t get the post ID since the action only returns the following four arguments: $valid, $value, $field, $input.
So, @Elliot Condon, any way to get the post ID inside acf/validate_value/name=[field_name]?
The topic ‘ACF PRO: Possible bug in acf/save_post’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.