Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Forum: Hacks
    In reply to: Post version issues

    wpAdm, you might want to try the title_save_pre filter hook (and maybe others like name_save_pre).
    e.g.:

    add_filter( 'title_save_pre', 'change_the_title' );
    function change_the_title($title_to_ignore) {
    	$real_title = "whatever you want";
    	return $real_title;
    }

    It will run just before the post is saved to the database, but since it only filters instead of actually performing any “action”, it won’t cause an infinite loop. You’ll still want to attach to save_post for actually saving any custom fields, but you’ll be able to pull those fields from the $_POST again within the filter if you need them for generating your custom title.

    Perhaps you’ve already solved this by now, but in case anyone else has a similar problem, I’ll mention how I got past it in my case. Instead of attaching to any actions, I used the title_save_pre and name_save_pre filter hooks. Something like this might work in place of the code above:

    add_filter('title_save_pre', 'save_title');
    function save_title($title_to_ignore) {
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$event_team = $custom["event_team"][0];
    	$event_opponent = $custom["event_opponent"][0];
    	$event_date = $custom["event_date"][0];
    	$my_post_title = $event_team . " vs. " . $event_opponent . " - " . $event_date;
    	return $my_post_title;
    }
    
    add_filter('name_save_pre', 'save_name');
    function save_name($name_to_ignore) {
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$event_team = $custom["event_team"][0];
    	$event_opponent = $custom["event_opponent"][0];
    	$event_date = $custom["event_date"][0];
    	$my_post_name = $event_team . "-vs-" . $event_opponent . "-" . $event_date;
    	return $my_post_name;
    }
Viewing 2 replies - 1 through 2 (of 2 total)