Advertisement
Viper007Bond

Untitled

Aug 29th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php
  2.  
  3. require( 'wp-load.php' );
  4.  
  5. set_time_limit( 0 ); // This is gonna take a while...
  6.  
  7. $posts = get_posts( array(
  8.     'category_name' => 'm', // category slug
  9.     'posts_per_page ' => -1, // all posts
  10. ) );
  11.  
  12. foreach ( $posts as $post ) {
  13.     // Easier to get cat IDs using get_the_terms than get_the_category()
  14.     $categories = array_keys( get_the_terms( $post->ID, 'category' ) );
  15.  
  16.     // Add the new category to the post's existing categories
  17.     $categories[] = 123; // the ID of the category to add
  18.  
  19.     $updated_post = array();
  20.     $updated_post['ID'] = $post->ID;
  21.     $updated_post['post_category'] = $categories;
  22.  
  23.     wp_update_post( $categories );
  24. }
  25.  
  26. echo 'Done!';
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement