Skip to content

Instantly share code, notes, and snippets.

@luancmaia
Last active September 8, 2017 15:56
Show Gist options
  • Save luancmaia/b58b7ec8280a49cb1625c2d6114b8ac1 to your computer and use it in GitHub Desktop.
Save luancmaia/b58b7ec8280a49cb1625c2d6114b8ac1 to your computer and use it in GitHub Desktop.
Update post tags
add_action( 'init', 'update_post_tags' );
function update_post_tags() {
$q = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1 ) );
if ( $q->have_posts() ):
while ( $q->have_posts() ):
$q->the_post();
$post_id = get_the_ID();
$args = array( 'fields' => 'names' );
$categories = wp_get_post_categories( $post_id, $args );
$cat_names = implode( ', ', $categories );
wp_set_post_tags( $post_id, $cat_names, true );
endwhile;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment