Support

Account

Home Forums ACF PRO Edit Slug in ACF Form Reply To: Edit Slug in ACF Form

  • Hi @frankster1234

    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 🙂