Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
Created July 13, 2013 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkingorg/5991415 to your computer and use it in GitHub Desktop.
Save alexkingorg/5991415 to your computer and use it in GitHub Desktop.
Find all posts in converted categories and threads and add a "projects" category to them.
<?php
function akv3_add_projects_cat() {
// find all posts in converted categories and threads
$term_ids = array(400, 417, 438, 455, 13, 14, 15, 20, 22, 52, 53, 58, 59);
$query = new WP_Query(array(
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'projects',
'field' => 'id',
'terms' => $term_ids,
'operator' => 'IN'
)
)
));
// add "projects" cat to those posts
foreach ($query->posts as $post) {
wp_set_object_terms($post->ID, 'projects', 'category', true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment