Last active
September 8, 2017 15:56
-
-
Save luancmaia/b58b7ec8280a49cb1625c2d6114b8ac1 to your computer and use it in GitHub Desktop.
Update post tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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