I have the following snippet that allows me to auto generate the post title. I'd like to change the $post_type
of the 'post_title' => $post_type . ' Job #' . $post_id
line to some other post property like post_date
and post_author
.
function save_post_func_2134( $post_id ) {
$post_type = 'post'; //Change your post_type here
if ( $post_type == get_post_type ( $post_id ) ) { //Check and update for the specific $post_type
$my_post = array(
'ID' => $post_id,
'post_title' => $post_type . ' Job #' . $post_id //Construct post_title
);
remove_action('save_post', 'save_post_func_2134'); //Avoid the infinite loop
// Update the post into the database
wp_update_post( $my_post );
}
}
add_action( 'save_post', 'save_post_func_2134' );