Tipically. Snippet to prevent duplicate slugs makes it.
function bhrs_save_post_callback( $post_ID, $post, $update ) {
if (in_array($postarr['post_type'], array('post', 'page', 'chronik', 'mitglied', 'galerie', 'vorstand', 'event')) &&
!in_array($data['post_status'], array('publish', 'draft', 'pending', 'auto-draft', 'future', 'private', 'trash')))
return;
// unhook this function to prevent infinite looping
remove_action( 'save_post', 'bhrs_save_post_callback', 10, 3 );
// update the post slug (WP handles unique post slug)
wp_update_post( array(
'ID' => $post_ID,
'post_name' => ''
));
// re-hook this function
add_action( 'save_post', 'bhrs_save_post_callback', 10, 3 );
}
add_action( 'save_post', 'bhrs_save_post_callback', 10, 3 );
This one leave ACF slugs alone:
// Force slug auto generate
function myplugin_update_slug( $data, $postarr ) {
if (in_array($postarr['post_type'], array('post', 'page', 'chronik', 'mitglied', 'galerie', 'vorstand', 'event')) &&
!in_array($data['post_status'], array('publish', 'draft', 'pending', 'auto-draft', 'future', 'private', 'trash'))) {
$data['post_name'] = sanitize_title( $data['post_title'] );
}
return $data;
}
add_filter( 'wp_insert_post_data', 'myplugin_update_slug', 9, 2 );