Home › Forums › General Issues › Fields not saving – Slug › Reply To: Fields not saving – Slug
Thanks for reply.
This one seems to work. If someone wants to make it shorter or better please be free to do it.
// Force slug auto generate
function myplugin_update_slug( $data, $postarr ) {
if ( 'page' === $postarr['post_type'] || 'post' === $postarr['post_type'] || 'attachment' === $postarr['post_type'] && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
$data['post_name'] = sanitize_title( $data['post_title'] );
}
return $data;
}
add_filter( 'wp_insert_post_data', 'myplugin_update_slug', 99, 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.