I am new to WP and I couldn't find this solution by myself.

this is my function,

function explodetitletotags() {

    global $post;

    $title = $post->post_title;

    $tags = explode(' ', preg_replace('/[^\p{L}0-9 ]/', ' ', $title)); 

    foreach $tags as $tag {

        global $post;

        $thePostID = $post->ID;

        wp_add_post_tags($thePostID, $tag);



add_action('publish_post', 'explodetitletotags');

The Function works like a charm except When the post title in the new single post page updated, the title always give the previous value, not the value the last time I typed in the input title box.

My assumption here is, $title = $post->post_title; in my function call the old version of the title from Database instead of the new version, I think why don't just grab the title before it sent to the Database so the title always the latest version, is this okay?

If yes, Is there a way to intercept/catch wordpress on Post-Save before it's saved in wp_posts table Database?

I am sorry for my English, since it's not my first tongue and Thank You for your help.

  • Can you explain why you want to do this? What it the result you want? It can effect the answer.
    – s_ha_dum
    Commented Dec 10, 2012 at 15:19
  • @s_ha_dum I plan to explode the post title and add them as post tags, thanks for dropping by
    – ded syd
    Commented Dec 10, 2012 at 15:48
  • After your edits I have to ask: have you read How to add terms to a post depending on its title?
    – fuxia
    Commented Dec 10, 2012 at 17:13

1 Answer 1


To set the title before it is saved, hook into wp_insert_post_data:

add_filter( 'wp_insert_post_data', 'wpse_75597_change_title' );

function wpse_75597_change_title( $post_data )
    $post_data['post_title'] = 'SOMETHING VERY LOUD';

    return $post_data;
  • thanks @toscho for the fast answer, but is there a way to catch the title before it's saved in the database without changing it?
    – ded syd
    Commented Dec 10, 2012 at 16:23
  • You can use almost the same code. Just save (copy) $post_data['post_title'] somewhere and return the $post_data without changing it.
    – fuxia
    Commented Dec 10, 2012 at 16:26

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.