Skip to content

Instantly share code, notes, and snippets.

@nielsvr
Last active December 23, 2015 04:28
Show Gist options
  • Save nielsvr/6580063 to your computer and use it in GitHub Desktop.
Save nielsvr/6580063 to your computer and use it in GitHub Desktop.
Move posts from cat1 to cat2
<?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