Last active
August 29, 2015 14:06
-
-
Save abrudtkuhl/bcae8f0aff35e0800abf to your computer and use it in GitHub Desktop.
WordPress Apply new category to all existing posts
This file contains hidden or 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_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