Set post title from two meta fields

You are using wrong variable on the following line:

$data['post_title'] = $post_title;

you should use $event_title in $post_title as following:

$data['post_title'] = $event_title;

Also Get Post ID from $postarr parameter.

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 );

For more information on this filter visit this page.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)