I think save_post
action hook is the proper one. Maybe you’ll want to insert some checking if the post title is already set ($post_object->post_title
), as this code always update the title according to the content.
add_action( 'save_post', 'save_post_wpse_87921', 10, 2 );
function save_post_wpse_87921( $post_id, $post_object )
{
// Auto save?
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// Correct post_type
if ( 'servicestatus' != $post_object->post_type )
return;
$new_title = wp_trim_words( $post_object->post_content, $num_words = 10, $more="" );
// Unhook this function so it doesn't loop infinitely
remove_action( 'save_post', 'save_post_wpse_87921' );
// Call wp_update_post update, which calls save_post again.
wp_update_post( array(
'ID' => $post_id,
'post_title' => $new_title
));
add_action( 'save_post', 'save_post_wpse_87921', 10, 2 );
}