您在以下行中使用了错误的变量:
$data[\'post_title\'] = $post_title;
您应该在$post\\U标题中使用$event\\U标题,如下所示:
$data[\'post_title\'] = $event_title;
还可以从$postarr参数获取Post ID。
Updated Code :
function set_event_title( $data , $postarr ) {
if($data[\'post_type\'] == \'events\') {
$event_date = get_post_meta($postarr[\'ID\'],\'event_datetime\',true);
$event_venue = get_post_meta($postarr[\'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\'] = $event_title;
$data[\'post_name\'] = $post_slugsan;
}
return $data;
}
add_filter( \'wp_insert_post_data\' , \'set_event_title\' , \'10\', 2 );
有关此筛选器的详细信息,请访问
this page.