Home › Forums › ACF PRO › Edit Slug in ACF Form › Reply To: Edit Slug in ACF Form
I believe you can create a dummy text field so you can input the slug you want and then add a function to change the post slug on save like this:
function my_acf_save_post( $post_id ) {
$new_slug = get_field('dummy_slug_custom_field');
$my_post = array(
'ID' => $post_id,
'post_name' => $new_slug,
);
remove_action('acf/save_post', 'my_acf_save_post', 20);
wp_update_post( $my_post );
add_action('acf/save_post', 'my_acf_save_post', 20);
wp_redirect( get_permalink($post_id) );
exit;
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
Where “dummy_slug_custom_field” is the dummy custom field for the post slug.
I hope this helps 🙂
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.