Skip to content

Instantly share code, notes, and snippets.

@abrudtkuhl abrudtkuhl/functions.php
Last active Aug 29, 2015

What would you like to do?
WordPress Apply new category to all existing posts
add_action( 'init', 'update_taxonomy');
function update_taxonomy() {
$posts = get_posts(
'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
You can’t perform that action at this time.