Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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;
$wpdb->query($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;
share|improve this answer
    
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 –  Paul Thomson May 16 '13 at 8:58
    
I have updated my code to filter the category. –  Noor Ahmad Feroozi May 16 '13 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. –  Paul Thomson May 17 '13 at 9:58
    
Hi Paul, I just updated my to your requirement, Make sure you backup your data before using it. –  Noor Ahmad Feroozi May 19 '13 at 12:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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