How to auto increment post title & post slug field?

I did not work it out using save_post or any other save-filter, so as I am only needing to do the same for the title, I used the default_title filter. This means that it works for drafts as well.

add_filter( 'default_title', 'change_title', 10, 2 );
function change_title( $title, $post ) {
    return 'PO' . $post->ID;
}

Notice that here I am using the newly created post’s ID, so I don’t have to fetch $last_post_id as you do, and perhaps you don’t have to do that either if you do it like this. Remember to check the post type before changing the title though.

I have not tested to do the same with the slug, but I noticed there is a similar filter for the slug, called wp_unique_post_slug. Hopefully this will help you. 🙂

Edit: here is the filter from WP Core code, https://developer.wordpress.org/reference/functions/wp_unique_post_slug/