Auto-Tagging a Custom Post Type

Referenced from https://codex.wordpress.org/Post_Status_Transitions#.7Bstatus.7D_.7Bpost_type.7D_Hook the hook named “{status}_{post_type} Hook”. This hooks is fired, when custom post type “community” is giving the status “publish” = is published. Hook will give post_id and post object as parameters to the callback function. And wp_set_post_terms, requires first parameter as post ID.

This should work:

    add_action('publish_community', 'community_post_type_tagging', 10, 2);
    function community_post_type_tagging($post_id, $post){
        wp_set_post_terms( $post_id, 'community', 'post_tag', true )    
    }

tech