Skip to content

Instantly share code, notes, and snippets.

@constantin-b
Last active May 30, 2017 19:12
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 constantin-b/3b0fd6caa7192c436dc3a40b9dacc1a3 to your computer and use it in GitHub Desktop.
Save constantin-b/3b0fd6caa7192c436dc3a40b9dacc1a3 to your computer and use it in GitHub Desktop.
WP plugin YouTube Hub - add extra WP categories to already existing video posts that will be skipped from importing to avoid duplicates
/**
* Add extra categories to existing posts
* @param $posts - array of posts
* @param $taxonomy - the category taxonomy
* @param $category - the category to add
*/
function cbc_add_categories( $posts, $taxonomy, $category ){
if( !is_array( $posts ) ){
$posts = array( $posts );
}
foreach( $posts as $post ){
if( $category ){
wp_set_post_terms( $post->ID, $category, $taxonomy, true );
}
}
}
add_action( 'cbc_skipped_posts_category', 'cbc_add_categories', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment