<?php
/*
Plugin Name: AutoSave WordPress Title As Tags
Plugin URI: http://fusedthought.com/archives/tutorial-autosave-wordpress-post-title-as-tags/
Description: Automatically save WordPress post title as tags
Author: Gerald Yeo
Author URI: http://fusedthought.com
Version: 0.2
*/

function SaveTitleAsTag($post_ID) {
	$gpt = get_post($post_ID); 
	$posttitle = $gpt->post_title;
	$posttitle = strtolower($posttitle);
	if(get_the_tags($post_ID)){
		foreach(get_the_tags($post_ID) as $tag) {
			$tag_name = $tag->name;
			$tag_name  = strtolower($tag_name);
			$posttitle = str_replace($tag_name, "", $posttitle);
		} 
	}
	$splittotags = explode(" ", $posttitle);
	foreach ($splittotags as $atag){
		$atag = str_replace(" ", "", $atag);
		if($atag !=NULL){
			wp_set_object_terms($post_ID, $atag, 'post_tag', true );
		} 
	}
	//update_post_meta($post_ID, 'getthetag', $gettags);
}

add_action('save_post', 'SaveTitleAsTag');
?>
