Change custom post title before publishing
<p>I have a custom post named <code>session</code> where there are some custom fields such as <code>date</code>, and <code>event_location</code>.</p>

<p>I want to generate a title for this custom post, with the following code :</p>

<pre><code>add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 );

function modify_post_title( $data , $postarr )
{
  if($data['post_type'] == 'session') {

  //the id of the post
  $post_id = $postarr['ID'];

  //the date
  $date = get_post_meta( $post_id, 'session_date', true );

  //the location
  $event_location = get_post_meta( $post_id, 'session_location', true );

  //concatenating location and date
  $data['post_title'] = "$event_location-$date";
  }

  //returning the data
  return $data;
}
</code></pre>

<p>In order to make it work, i.e. in order to have a properly "forged" title used as a permalink (such as www.mysite.com/session/toronto-04282016), here is what I must do :</p>

<ul>
<li>create a new session and fill the required custom fields </li>
<li>save it as a draft</li>
<li>reload the page where the session was edited</li>
<li>publish the session post</li>
</ul>

<p>If I try to publish directly the custom post, its permalink takes the #id of the post such as : www.mysite.com/session/432.</p>

<p>EDIT : and the custom post title is empty</p>

<p>EDIT #2 : in the admin panel, if I click on update for a "directly published" custom post, its permalink and title take the "correct" form.</p>

<p>How can I do to be able to publish a new session with a custom title without using the draft step ?</p>

<p>Maybe the filter is not called when a custom post "session" is published. How can I force it to be called ?</p>