Title: Creating new Event Tags through Code
Last modified: April 17, 2023

---

# Creating new Event Tags through Code

 *  Resolved [murdochactive](https://wordpress.org/support/users/murdochactive/)
 * (@murdochactive)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/creating-new-tags-through-code/)
 * Hi there,
   I was wondering if it is possible to add Event Tags through code as
   opposed to through the Event Tag menu. I have a list of clubs in a seperate database,
   and I want to add a button through my own plugin that will call a function which
   will access whatever mechanism there is for adding event tags, iterate through
   the data in my database and add them in as tags.I already know how to loop through
   my own data and access functions in the Events Manager plugin, I just can’t seem
   to figure out if the Events Manager plugin has a function for adding tags (I 
   assume it does, just don’t know where to find it).Cheers!
    -  This topic was modified 3 years, 1 month ago by [murdochactive](https://wordpress.org/support/users/murdochactive/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [murdochactive](https://wordpress.org/support/users/murdochactive/)
 * (@murdochactive)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/creating-new-tags-through-code/#post-16697101)
 * Just giving this a bit of a bump since I’m still trying to find a solution
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/creating-new-tags-through-code/#post-16698463)
 * I don’t see a function for adding tags.
 * Here’s some code to import events from a csv file (in the function importEventsCSV):
   [https://github.com/webaware/events-manager-import-export/blob/master/includes/class.EM_ImpExpImport.php](https://github.com/webaware/events-manager-import-export/blob/master/includes/class.EM_ImpExpImport.php)
 * The code is pretty old so it doesn’t have code to handle tags but it does handle
   categories. I think tags can be handled is a way similar to categories. Just 
   use EM_Tag instead of EM_Category. When calling wp_insert_term use ‘event-tags’
   instead of ‘event-categories’.
 * Also you wouldn’t call $eventcats = $event->get_categories();.
 * I see the following code in events-manager/classes/em-event.php:
 *     ```wp-block-code
                           //general taxonomies including event tags
                           $terms = get_the_terms( $this->post_id, $tax_data['name']);
                           $term_slugs = array();
                           if( is_array($terms) ){
                               foreach($terms as $term){
                                   if( !empty($term->slug) ) $term_slugs[] = $term->slug; //save of category will soft-fail if slug is empty
                               }
                           }
                           foreach($post_ids as $post_id){
                               wp_set_object_terms($post_id, $term_slugs, $tax_data['name']);
                           }
       ```
   
    -  This reply was modified 3 years, 1 month ago by [joneiseman](https://wordpress.org/support/users/joneiseman/).
 *  Thread Starter [murdochactive](https://wordpress.org/support/users/murdochactive/)
 * (@murdochactive)
 * [3 years ago](https://wordpress.org/support/topic/creating-new-tags-through-code/#post-16790562)
 * Hey [@joneiseman](https://wordpress.org/support/users/joneiseman/) 
   Cheers for
   the reply! Still trying to figure things out, but I have been looking through
   what you’ve sent me as well. The main issue is that I’m trying to make the process
   as simple as possible for the people running the backend of this site as they
   are not developers themselves, and the more steps I add in, the more likely it
   is that something may get stuffed up. I do see what your getting at though, there
   doesn’t appear to be a system for adding tags through code directly, but you 
   can add them through events, so I maybe have an idea but I’ll need to see how
   it goes.My idea is maybe make a dummy event that I can use to add tags through,
   and then once the tag has been added using it, delete the dummy event. I don’t
   know if it’ll work but maybe thats a workaround for now.Cheers for the advice
   though!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Creating new Event Tags through Code’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [murdochactive](https://wordpress.org/support/users/murdochactive/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/creating-new-tags-through-code/#post-16790562)
 * Status: resolved