• Resolved ashishodich

    (@ashishodich)


    I want to add predefined category for event.
    How can I add category to newly created event using theme’s functions.php file?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Ashish,

    In order to create a category, you can refer to the doc:https://wp-eventmanager.com/knowledge-base/add-a-new-event-category/

    This will help you create an event category from the backend and assign the same to your events.

    Regards,
    Priya

    Thread Starter ashishodich

    (@ashishodich)

    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 3 years, 6 months ago by ashishodich.

    HI @ashishodich

    Thanks for reaching out to us, however, at this time, we don’t have the bandwidth to complete your request. As per the support policy, we do not provide customization.

    I would recommend taking a look at our community forum:
    Facebook: https://www.facebook.com/groups/wpeventmanager/
    Slack: http://wpeventmanager.slack.com/
    GitHub: https://github.com/wpeventmanager/wp-event-manager

    There, you can find other users who may be experiencing a similar roadblock, and hence help you achieve your solution by providing some help.

    Regards,
    Priya

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I add static category from theme’s functions.php file?’ is closed to new replies.