In a custom post type I have post titles disabled, however in the list of posts and in the slug it just shows the title as "auto-draft". I want to automatically take two pieces of post-meta and make then the title and the slug.
I thought this would work, but I can't make it happen:
function set_event_title( $data , $postarr ) {
if($data['post_type'] == 'events') {
$event_date = get_post_meta($post_id,'event_datetime',true);
$event_venue = get_post_meta($post_id, 'venue_name' , true);
$event_title = $event_venue . ' - ' . $event_date;
$post_slug = sanitize_title_with_dashes ($event_title,'','save');
$post_slugsan = sanitize_title($post_slug);
$data['post_title'] = $post_title;
$data['post_name'] = $post_slugsan;
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'set_event_title' , '99', 2 );
Anyone know how I might get it to do its thing correctly?