I'm looking to move a number of old posts by one author from one category to another category and was hoping someone could help me do this?

I figure the easiest way would be through an SQL command?

I'm aware that you can bulk 'move' posts via the post editor screen but this only adds another category and doesn't in fact move the posts. There are a number of different plugins out there that can bulk move posts but none of them allow you to select specific users and specific dates.

In essence what I'm trying to achieve:

  • select all posts from user with ID: 2
  • IF posts are made before 15 Feb 2012 AND in category XYZ THEN move to category ABC

Any help would be greatly appreciated.

1 Answer 1


Try something like this:

global $wpdb;
$from_user = 2;
$to_user = 5;
$posts_table = $wpdb->prefix . 'posts';
$users_table = $wpdb->prefix . 'users';
$strQuery = "UPDATE `$posts_table` SET post_author = $to_user WHERE post_author = $from_user AND $posts_table.post_date < '01/01/2013' AND $wpdb->term_taxonomy.term_id IN (1,2,3) AND $wpdb->term_taxonomy.taxonomy = 'category'";
echo $strQuery;

For more info please visit this link

Edit Move all posts from one category to another category based on time and author and post

$args = array(  
                'category_name' => 'Category 1', 
                'author_name=' => 'Noor Ahmad Feroozi',
                'year' => date('Y'),
                'month' => date('n')

$posts = new WP_Query( $args );
if ( $posts->have_posts() ) : while ($posts->have_posts()) : $posts->the_post();
    wp_set_object_terms(get_the_ID(), 'Category 2', 'category');
endwhile; endif;
  • thanks for providing the code but I need to move the categories where the post is located. From category A to category B for a specific User when the post is older than X date... are you able to update the code? Thanks, Paul Commented May 16, 2013 at 8:58
  • I have updated my code to filter the category.
    – Core
    Commented May 16, 2013 at 10:26
  • Hi Noor, This still seems to be updating the author of the post and not the category. I need to bulk change the category of the posts dependant on when it was posted and the author. Commented May 17, 2013 at 9:58
  • Hi Paul, I just updated my to your requirement, Make sure you backup your data before using it.
    – Core
    Commented May 19, 2013 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.