• Resolved murdochactive

    (@murdochactive)


    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter murdochactive

    (@murdochactive)

    Just giving this a bit of a bump since I’m still trying to find a solution

    joneiseman

    (@joneiseman)

    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

    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:

                        //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 ago by joneiseman.
    Thread Starter murdochactive

    (@murdochactive)

    Hey @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.