Adding Information to Events on Load

This tutorial forms part of our series of tutorials for creating an custom add-on for Events Manager called “Styles”, where we will be able to select from a list of styles during event registration. In our previous tutorial, we had added some php to save extra event information during event registration

If you decided to create extra information about events and integrate it into Events Manager, you’ll certainly want that information available for retrieval when accessing an event’s details.

In this case, our events have styles associated with them in the em_meta table, and we want that information loaded when event information is loaded. In order for this to happen, we’ll need to create a small function that adds this meta information after an event has finished loading.

function my_em_styles_event_load($EM_Event){
	global $wpdb;
	$EM_Event->styles = $wpdb->get_col("SELECT meta_value FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->event_id}' AND meta_key='event-style'", 0	);

The em_event action is called just after an event has been called, and passes on the newly created object. This is the perfect opportunity for us to query the meta table and grab any styles associated with that ID. Remember to take recurring events into consideration by checking the event with the is_recurring() function.

Now, we can easily access that event’s style information by calling the object ‘style’ property, which will contain a numeric array of all the styles ids of this event. Now that we can add styles and attach them to our events, it’s time to start doing something with them!

In our next tutorial, we’re going to make styles accessible as searchable arguments in shortcodes, template tags and EM objects by creating custom event search attributes.