Saving with this:
add_filter('em_event_save','my_em_groups_event_save',1,2);
function my_em_groups_event_save($result,$EM_Event){
global $wpdb;
$my_em_groups = (is_array(get_option('my_em_groups'))) ? get_option('my_em_groups'):array();
if( $result && !empty($_POST['event_groups']) ){
$ids_to_add = array();
$EM_Event->groups = array();
foreach( $_POST['event_groups'] as $group_id ){
if( array_key_exists($group_id, $my_em_groups) ){
$ids_to_add[] = "({$EM_Event->id}, 'event-group', '$group_id')";
$EM_Event->groups[] = $group_id;
}
}
//First delete any old saves
$wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->id}' AND meta_key='event-group'");
if( count($ids_to_add) > 0 ){
$wpdb->query("INSERT INTO ".EM_META_TABLE." (object_id, meta_key, meta_value) VALUES ".implode(',',$ids_to_add));
}
}
return $result;
}
tried adding this below it in addition
add_filter('em_event_save_events','my_em_groups_rec_event_save',1,2);
function my_em_groups_rec_event_save($result,$EM_Event){
global $wpdb;
$my_em_groups = (is_array(get_option('my_em_groups'))) ? get_option('my_em_groups'):array();
if( $result && !empty($_POST['event_groups']) ){
$ids_to_add = array();
$EM_Event->groups = array();
foreach( $_POST['event_groups'] as $group_id ){
if( array_key_exists($group_id, $my_em_groups) ){
$ids_to_add[] = "({$EM_Event->id}, 'event-group', '$group_id')";
$EM_Event->groups[] = $group_id;
}
}
//First delete any old saves
$wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->id}' AND meta_key='event-group'");
if( count($ids_to_add) > 0 ){
$wpdb->query("INSERT INTO ".EM_META_TABLE." (object_id, meta_key, meta_value) VALUES ".implode(',',$ids_to_add));
}
}
return $result;
}
I’m missing something, I know. The tables for recurring event “groups” aren’t being created. So it has to be obtaining the recurring event id’s and inserting VALUES for them. I tried defining events which have the current recurrence_id with something like this
$my_recurring_id = $wpdb->query("SELECT recurrence_id FROM ". EM_EVENTS_TABLE ." WHERE event_id ='{$EM_Event->id}' ");
$my_rec_event_id = $wpdb->query("SELECT event_id FROM ". EM_EVENTS_TABLE ." WHERE $my_recurring_id = recurrence_id ");
And then using those in the delete / insertion queries but no result.
Thanks for your thoughts.