Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.