Skip to content

Instantly share code, notes, and snippets.

@abrudtkuhl
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abrudtkuhl/bcae8f0aff35e0800abf to your computer and use it in GitHub Desktop.
Save abrudtkuhl/bcae8f0aff35e0800abf to your computer and use it in GitHub Desktop.
WordPress Apply new category to all existing posts
add_action( 'init', 'update_taxonomy');
function update_taxonomy() {
$posts = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1
)
);
// where 134 is new category ID
foreach ($posts as $post) {
wp_set_object_terms($post->ID, 134, 'category', true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment