Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-Tagging with Author Username
<?php
function wpized_tag_post_with_author_username($post_id) {
if($parent = wp_is_post_revision($post_id)) {
$post_id = $parent;
}
$post = get_post($post_id);
if($post->post_type != 'post') {
return;
}
$user = new WP_User($post->post_author);
if(!in_array('administrator', $user->roles)) {
wp_set_post_terms($post_id, $user->user_login, 'post_tag', true);
}
}
add_action('save_post', 'wpized_tag_post_with_author_username');
?>
@westonruter

This comment has been minimized.

Copy link

@westonruter westonruter commented Feb 3, 2012

Might want to do if( !in_array('administrator', $user->roles) ) just in case they have more than one role, which I've never seen, but still :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment