I have been researching how to automatically tag a post by author, so if "Peter Parker" authors a post, that post would automatically show up with a tag "Peter Parker." This is because I will have a multi-author blog with custom post types picked up by various blog rolls, and don't want to leave it up to users to remember to tag themselves in every single post.
I came across this thread that seemed to be asking the same thing as I'm doing now and ended up with the following code:
add_action( 'save_post', 'add_authors_name');
function add_authors_name( $post_id ) {
global $post;
$post_author = $post->post_author; // returns the Author ID
// get the author's WP_User object so we can get the Author Name
$post_author_obj = get_userdata( $post_author );
$post_author_name = $post_author_obj->first_name . ' ' . $post_author_obj->last_name;
wp_set_post_terms( $post_id, $post_author_name, 'post_tag', true );
}
I put this in functions.php and it broke my site. I had to login to the hosting company and reset the file through ftp.
I then came across this thread that also provided an acceptable (albeit more messy) approach that would automatically assign authors to specific categories. That lead me to a plugin that someone replied with but that was from 3 years ago and the plugin no longer worked when I tried to install/activate it.
I then searched more on google but only found a freelancer.com link that was requesting this kind of plugin be made.
I would appreciate your help. I've tried to do a good amount of research into this but ended up breaking my site or hit dead ends. Thank you.
edit: As I was able to explain thanks to cybmeta's helpful prompts, I do indeed want to eventually try my hand at customizing author.php, but right now I do not have enough know how to even formulate questions acceptable for stackexchange. This auto-tagging of authors is the last piece of the puzzle for me getting on with my site without coding anything else, so I would be grateful for assistance with that. Thank you so much for your help so far, cybmeta.
$post->post_author
). I don't get the point of creating a tag with the author name. What is the purpose of doing it?