Custom Post-Rename Function Does Not Function in WordPress 6.x

Question

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 this should do is grab the (publish) date and time and set that to the title and slug for the listed post types. This worked precisely as expected until recently. For some reason, this function no longer works in WordPress 6.x (as of writing this, WordPress 6.0.3).

Nothing relevant seems to appear in any logs. What change or changes caused this to break? and what needs to be updated to get it working again?

0
Zyniker 1 month 2022-10-26T23:17:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse