Home › Forums › Backend Issues (wp-admin) › how to detect if post is new or edited with pre_save_post()? › Reply To: how to detect if post is new or edited with pre_save_post()?
Well, the acf/pre_save_post hook does not run in the admin.
There really isn’t any way to tell if the post is a new post or being updated during acf/save_post. The only way that you’ll be able to do this is to… to be honest, I’m not sure.
You can either set a flag that says tells you or you can possible check the file that you unzipped to see if it exists.
I don’t know how to do the second one, possibly get the attachment and see if it’s a .zip or something else. I’m not exactly sure about the unzipping a file since you can’t know what it contains, so it’s not very secure.
You could set a hidden meta value, you hide meta values by starting the name with an underscore.
To add to the conditions
if (!is_numeric($post_id) || get_post_type($post_id) != 'files') {
return;
}
$done_this = get_post_meta($post_id, '_done_this', true);
if ($done_this) {
// we already did the unzipping, don't do it again
return;
}
// set the value so we won't do it again
update_post_meta($post_id, '_done_this', true);
// now do the file unzipping
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.