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);
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.