Custom post-rename function WordPress 6.x . does not work in

I have the following function in functions.php in a child theme:

<?php
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 ); // Grabs the inserted post data so you can modify it.
function modify_post_title( $data ){
    if($data['post_type'] == 'post' || $data['post_type'] == 'remark' || $data['post_type'] == 'share' && !get_page_by_title($data['post_title'],OBJECT, 'post')){
        $id = get_the_ID();
        $new_title = get_the_time( 'Y-m(M)-d(D)—HiT', $id );
        $new_slug = get_the_time( 'Y-m-d-HiT', $id );

        $data['post_title'] =  $new_title;
        $data['post_name'] = strtolower($new_slug); // Updates the post slug to the new title.
    }
    return $data;
}

What is this should do(published) grabs the date and time and sets it to the title and slug for the post types listed. It worked just as expected until recently. For some reason, this function no longer works in WordPress 6.x (WordPress 6.0.

Nothing relevant appears in any of the logs. What change or change caused it to break? And what needs to be updated to get it working again?

Leave a Comment