Home › Forums › General Issues › acf/save_post issue/alternatives
I’m having an issue with this hook acf/save_post
as when I create my function it goes through various logic checks. On occasion if it does not meet conditions and I exit the function, it will save a post, but no field data information will be passed.
What I would like is for the function to die, or not to create these extra empty posts. Is there another function I can use? Would acf/pre_save_post
be a better option? I’m just not sure why its creating these empty post entries with no data.
Hi @ahowell1
acf/save_post is essentially just a hook that replicates wp cores save_post which runs after a post has been initially saved.
So when you’re hooking into that and try to abort a save you’re actually not preventing the post from being saved.
Is this a front-end form you’re using to create posts with?
Thanks for the help, yes, its a front end form. Is there a hook that triggers before the post is inserted into the database?
Although it doesn’t particularly solve my problem as I wanted I guess adding the wp_delete_post($post_id)
under failed conditionals will get rid of the empty posts, if otherwise, someone can correct me on that. Should I also add it in the condition that checks if $_POST['acf']
is empty before the return?
I think you need to supply more information or try to help yourself finding hooks in the WordPress codex.
To help you along, regarding a hook on a new post insertion, you can use ‘wp_insert_post’:
function wp_insert_post_hook( $post_ID, $post, $update )
{
$some_condition = true;
if ( $some_condition )
wp_delete_post( $post_ID );
}
add_action( 'wp_insert_post', 'wp_insert_post_hook', 10, 3 );
I think this is the hook you’re after:
http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data
The topic ‘acf/save_post issue/alternatives’ 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.