I create the title of the custom-post-type "produktionsauftrag" automatically. The script in my functions.php works but i cant get the postid at the end of my title.

Filter in my functions.php file:

function update_pa_title($data, $postarr) {
global $post;
  if ( !is_admin() )
        return $data;

    if ($data['post_type'] == 'produktionsauftrag') {

        $data['post_title'] = 'Produktionsauftrag - ' . $post_id;

        return $data;
    } else {
        return $data;

2 Answers 2


The filter "wp_insert_post_data" runs before the data is inserted into the database. When you create a new post, the ID is not set yet, it is set by the auto_increment field in the database.

You can use a filter or action later in the process like save_post.


I found the solution with title_save_pre

function auto_generate_post_title($title) {
   global $post;
   if (isset($post->ID)) {
      if (empty($_POST['post_title']) && 'produktionsauftrag' == get_post_type($post->ID)){
         // get the current post ID number
         $id = get_the_ID();
         // add ID number with order strong
         $title = 'produktionsauftrag-'.$id;} }
   return $title; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.