Title: Modifying Title Before Saving Custom Post
Last modified: August 20, 2016

---

# Modifying Title Before Saving Custom Post

 *  Resolved [cacheflowdesign](https://wordpress.org/support/users/cacheflowdesign/)
 * (@cacheflowdesign)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/modifying-title-before-saving-custom-post/)
 * I’m trying to find an efficient way to modify both the title and slug of custom
   post type. I would like to systematically generate a title based on a custom 
   meta data value and the post id. Both the title would be something like {metadata-
   value}-{post-id}. For this custom post type, I don’t want my user to be able 
   to set the title so I’ve disabled it on the ‘Edit Post’ screen.
 * Modifying the title dynamically seems to be very tricky and searching for help
   has yielded few results. My first instinct was to hook into the save_post action,
   but I don’t know how to set the title once I’m there. I’d prefer not to create
   a custom meta data field like ‘custom-title’, I’d like to modify the actual title
   prior to saving if possible.
 * Any ideas?

Viewing 1 replies (of 1 total)

 *  Thread Starter [cacheflowdesign](https://wordpress.org/support/users/cacheflowdesign/)
 * (@cacheflowdesign)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/modifying-title-before-saving-custom-post/#post-2359814)
 * Found it!
 * I used the filter wp_insert_post_data, checked to make sure it was my custom 
   post type, then set the title. The filter executes just before inserting data
   into the database, so I was good to go.
 *     ```
       add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 );
   
       function modify_post_title( $data , $postarr )
       {
         if($data['post_type'] == '{custom post type}') {
           $data['post_title'] = 'New Title';
         }
         return $data;
       }
       ```
   
 * I pulled the code from [http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data](http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data),
   I don’t know what the ’99’ and 2 parms are in the call to add_filter, but it 
   works.

Viewing 1 replies (of 1 total)

The topic ‘Modifying Title Before Saving Custom Post’ is closed to new replies.

## Tags

 * [post_title](https://wordpress.org/support/topic-tag/post_title/)
 * [save_post](https://wordpress.org/support/topic-tag/save_post/)
 * [title](https://wordpress.org/support/topic-tag/title/)

 * 1 reply
 * 1 participant
 * Last reply from: [cacheflowdesign](https://wordpress.org/support/users/cacheflowdesign/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/modifying-title-before-saving-custom-post/#post-2359814)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
