I have a Wordpress custom post type "Featured Book", which uses a subtitle to specify title of the book. Eg: "Featured Book: The Hunger Games"
Is it possible to automatically set the title of the post as "Featured Book" ?
I found this code through Googling but it does not work (Wordpress backend returns a blank page/white screen of death)
Is there some syntax error in the code, or is this just not possible?
function add_custom_title( $data, $postarr ) {
if($data['post_type'] == 'featured-book') {
if(empty($data['post_title'])) {
$data['post_title'] = 'Featured Book';
}
}
return $data;
}
add_filters('wp_insert_post_data', 'add_custom_title', 10, 2 );