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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 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.