Last active
December 23, 2015 04:28
-
-
Save nielsvr/6580063 to your computer and use it in GitHub Desktop.
Move posts from cat1 to cat2
This file contains 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
<?php | |
ini_set("display_errors", 1); | |
ini_set("error_reporting", E_ALL); | |
set_time_limit( 0 ) | |
require 'wp-load.php'; // in case you place it in a seperate file | |
$args = array( | |
'category_name' => 'cat1', | |
'posts_per_page' => -1, | |
'meta_query' => array( | |
array( | |
'key' => 'has_moved', | |
'compare' => 'NOT EXISTS' | |
) | |
) | |
); | |
$posts = new WP_Query( $args ); | |
echo "Still ".$posts->found_posts." posts to update"; | |
if ( $posts->have_posts() ) : | |
while ($posts->have_posts()) : | |
$posts->the_post(); | |
wp_set_object_terms(get_the_ID(), 'cat2', 'category'); | |
update_post_meta( get_the_ID(), "has_moved", mktime() ); | |
endwhile; | |
endif; | |
echo "Done!"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment