How to apply this 'auto post title' function to a specific post-type only
-
How would I apply this function to a specific post-type only, let’s say CPT XYZ?
add_action( 'save_post', 'wpse_214927_alter_title', 10, 2 ); function wpse_214927_alter_title ( $post_id, $post_object ) { // Remove the current action remove_action( current_filter(), __FUNCTION__ ); $post_date = $post_object->post_date; $format_date = DateTime::createFromFormat( 'Y-m-d H:i:s', $post_date ); $date_formatted = $format_date->format( 'Y-m-d' ); // Set correct to display here $post_author = $post_object->post_author; $author_name = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed $my_post = [ 'ID' => $post_id, 'post_title' => $author_name . ' Job ' . $date_formatted // Change as needed ]; wp_update_post( $my_post ); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to apply this 'auto post title' function to a specific post-type only’ is closed to new replies.