Home › Forums › Backend Issues (wp-admin) › Revisions dont’t work, get php errors… › Reply To: Revisions dont’t work, get php errors…
Thanks for the info @jenwachter .
FWIW, I’ll post here the fix to somewhat unrelated bugs I was experiencing with revisions that arose from trying to set the title of posts dynamically (based on ACF fields) on save.
If you try to set native WP fields in a save_post hook (or even acf_save_post), you’ll end up with “extra” bogus revisions, often which don’t restore properly, or restore but ignore ACF changed fields.
My fix was to listen for the wp_insert_post_data event, which I think ACF itself rides on, and make my change there, only referring to ACF fields by their ID since they wouldn’t be accessible via get_field at this point.
// Update dynamic title on save.
function bio_dynamic_title( $data, $postarr ) {
// Bail if this isn't the right post type or if ACF wasn't submitted.
if ( $data['post_type'] !== 'bio' || !array_key_exists( 'acf', $postarr ) ) {
return $data;
}
$title = sanitize_text_field( full_name(
$postarr['acf']['field_587e607692f49'], // first_name
$postarr['acf']['field_589a17cb1cdd3'], // middle_initial
$postarr['acf']['field_587e609192f4a'], // last_name
$postarr['acf']['field_587e6ee94602b'] // suffix
));
$data['post_title'] = $title;
$data['post_name'] = sanitize_title( $title );
return $data;
}
add_filter( 'wp_insert_post_data', 'bio_dynamic_title', 10, 2 );
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’re working hard on Advanced Custom Fields PRO 6.0, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) August 12, 2022
Featuring improved performance for Repeater fields with large datasets, and a new generation of ACF Blocks.
Let’s take a look 🧵https://t.co/Befre3kFAo
© 2022 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.