Hi Priya,
This method I know, But I want to add category to event based on rolewise using custom code as like following
`function remove_default_category($ID, $post) {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
}
//get all categories for the post
$categories = wp_get_object_terms($ID, ‘category’);
//if there is more than one category set, check to see if one of them is the default
if ($categories[0]->name == “Uncategorized”) {
foreach ($categories as $key => $category) {
//if category is the default, then remove it
if ($category->name == “Uncategorized”) {
wp_remove_object_terms($ID, ‘uncategorized’, ‘category’);
wp_set_object_terms( $ID, “fitness-health”, ‘category’);
}
}
}
}
//hook in to the publsh_post action to run when a post is published
add_action(‘publish_post’, ‘remove_default_category’, 10, 2);
Above is just an example…
Same way I want to add category to event while user create new event via code
-
This reply was modified 4 years, 1 month ago by ashishodich.