How we can make auto create tags/category from title when publising not save the page?
I try to modified this code:
add_action('save_post', 'add_title_as_category');
function add_title_as_category( $postid ) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
$post = get_post($postid);
if ( $post->post_type == 'page') {
$term = get_term_by('slug', $post->post_name, 'category');
if ( empty($term) ) {
$add = wp_insert_term( $post->post_title, 'category', array('slug'=> $post->post_name) );
if ( is_array($add) && isset($add['term_id']) ) {
wp_set_object_terms($postid, $add['term_id'], 'category', true );
}
}
}
}
This code work good when editing and then saving the page but not when "publising". I am using another plugin that create the pages and is not supporting the creation of Tags and categories.
I think the problem is the "save_post" but I try other function such as 'publish_post' from wordpress.org too.
If you have any idea on how to achieve this your more than welcome :)