Home › Forums › Backend Issues (wp-admin) › Gutenberg blocks – ACF does not save if key has "-" in value › Reply To: Gutenberg blocks – ACF does not save if key has "-" in value
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 );
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.