WordPress.org

Support

Support » Plugins and Hacks » Events Manager » [Resolved] how to add is_recurring for save data function

[Resolved] how to add is_recurring for save data function

Viewing 6 replies - 1 through 6 (of 6 total)
  • sorry, didn’t quite get what you mean; can I know what are you trying to achieved and can you give us more info.?

    sorry, yes.

    In the tutorial you created a meta box in which you can check the desired style when registering an event.
    I added an additional meta box that is displayed for recurring events by changing this (fyi, I have changed “styles” to “groups” in all instances):

    function my_em_groups_meta_boxes(){
    	add_meta_box('em-event-groups', 'Groups', 'my_em_groups_metabox',EM_POST_TYPE_EVENT, 'side','low');
    
    }

    to this

    function my_em_groups_meta_boxes(){
    	add_meta_box('em-event-groups', 'Groups', 'my_em_groups_metabox',EM_POST_TYPE_EVENT, 'side','low');
    	add_meta_box('em-event-groups', 'Groups', 'my_em_groups_metabox','event-recurring', 'side','low');
    }

    My question is, how do I make the meta box save the selections for recurring events? Right now it is not applying the checked values. I have to go back to each single event to apply the values.

    Plugin Author Marcus

    @netweblogic

    depends how you save your information, if you save it e.g. as post meta then it would be saved providing you added it before the events are saved e.g. during em_event_get_post_meta

    otherwise you’d need to added it with the em_event_save_events filter (search for it in classes/em-event.php for more info)

    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.

    Plugin Author Marcus

    @netweblogic

    chances are you need to get the last two parameters to identify the actual posts you need to add meta to:

    e.g. we trigger:

    apply_filters(’em_event_save_events’, true/false, $this, $event_ids, $post_ids);

    and loop those events to save your groups accordingly

    Really appreciate your advice, Marcus. Thanks. I’ll try it out.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] how to add is_recurring for save data function’ is closed to new replies.
Skip to toolbar