• Resolved Friedrich72

    (@friedrich72)


    I created this function to add styles to recurring events based on the walkthrough. I only have one style to choose from and I can’t uncheck it. I dont understand why the ‘…!empty($_POST[‘event_styles’])’ isnt checking for an empty box. I tried adding ‘… !empty($_POST[‘event_styles’]) && isset($_POST(‘event_styles’])’.
    I was wondering if you could point me in the right direction to be able to ‘uncheck’ the box?
    Heres the Save recurring styles function:

    add_filter('em_event_save','my_em_styles_recurring_event_save',1,2);
    
    function my_em_styles_recurring_event_save($result,$EM_Event){
    	global $wpdb;
    	$my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array();
    	if( $result && !empty($_POST['event_styles']) ){
    		$ids_to_add = array();
    		$EM_Event->styles = array();
    
    		foreach( $_POST['event_styles'] as $style_id ){
    
    			if( array_key_exists($style_id, $my_em_styles) ){
    
    		        if( $EM_Event->is_recurring() ){
    			        $receventids = $wpdb->get_col('SELECT event_id FROM '.EM_EVENTS_TABLE.' WHERE recurrence_id='.$EM_Event->id );
    				       foreach ($receventids as $receventid){
     		               $ids_to_add[] = "({$receventid}, 'event-style', '$style_id')";
    
    			           $EM_Event->styles[] = $style_id;
    			           }}else{
    
    	 		    $ids_to_add[] = "({$EM_Event->id}, 'event-style', '$style_id')";
    			   	$EM_Event->styles[] = $style_id;
    			}}
    		}
    		//First delete any old saves
    		$wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id={$EM_Event->id} AND meta_key='event-style'");
    		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;
    }

    Thanks for the help.

    https://www.ads-software.com/plugins/events-manager/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    instead of $_POST can you try $_REQUEST or can you check the contents of $_POST ?

    eg.

    print_r($_POST);

    Thread Starter Friedrich72

    (@friedrich72)

    Hi Angelo. I was able to figure this out.
    Thanks for the reply. It took a while to get back to you because trying ‘$_REQUEST’ didnt work. And i wasn’t sure how to get a result from ‘print_r($_POST).’ Where would you add that? I tried adding it to the meta box for styles but it just returned ‘Array().’ Tried adding it to the save function but it would have to go into an ‘alert’ pop up or something wouldnt it?

    My solution was simple, just took a while to realize it.
    I had to put an ‘else if’ after the initial ‘if’ statement in order for the save to determine what to do if ‘$_POST[‘event_styles’]’ was indeed empty. this code goes just before the ‘return $result’
    else if( empty($_POST['event_styles']) ){$wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id={$EM_Event->id} AND meta_key='event-style'");}

    Thanks again for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘styles uncheck’ is closed to new replies.