WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type called transaction, and on the post type's edit/publish screen I have removed the post title field. The post title is now being generated by the function below, which labels each post Transaction followed by a unique string, thanks to the uniqid PHP function.

I'm running this function on the title_save_pre filter but every time I update the post, a new unique number being generated for the title.

How can I modify the code below so that the unique number for the title is only generated once?

function transaction_title( $title ) {

  $screen = get_current_screen();
  $transaction_number = uniqid(); // unique number

  if ( 'transaction' == $screen->post_type ) {
     return 'Transaction '. $transaction_number;
  } else {
    return $title; // else return the normal title
add_filter( 'title_save_pre', 'transaction_title');

My initial thoughts are to set a post meta flag like this but I'm having trouble combining it with my function. It seems that it only updates the post meta when I use the transition_post_status action and doesn't with my title_save_pre filter (which I need to change the title).

share|improve this question
up vote 1 down vote accepted
function transaction_title( $title )

    if ( 'transaction' == get_current_screen()->post_type && '' == $title )
        return 'Transaction '.uniqid();
    // else return the normal title
        return $title;
add_filter( 'title_save_pre', 'transaction_title' );
share|improve this answer
Didn't seem to work, but thanks for the push in the right direction. Got it working now. Just needed to do a simple check on the title. – Andrew Jul 25 '12 at 21:55
In this case, just edit my answer and make it correct - at least this answers should help later users too :) – kaiser Jul 25 '12 at 21:56
Oops good point, I'll update yours now :) – Andrew Jul 25 '12 at 21:57

Have you tried using wp_insert_post_data() ? This question may also help you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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