Last active
May 30, 2017 19:12
-
-
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
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
/** | |
* 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