Change reccuring events at specfic date shortcode

[ad_1]

If someone has to chane a whole bunch of recurring events every year at a specific date. Here I can provide you an exampel shortcode how I did it. I changed it late to an do-action hook but to test it it would be easier this way 🙂

function update_event_data_shortcode($atts) {
    $current_date = date('d.m.Y');
	$current_year = date('Y');
	$next_year = date('Y', strtotime('+1 year'));
	
    if (isset($atts['event_id'])) {
		
        $event_id = intval($atts['event_id']);
		$EM_Event = em_get_event($event_id, 'event_id');
		
		$new_start_date = $next_year.'-04-01';
		$EM_Event->start_date = $new_start_date;

		$new_end_date = $next_year.'-10-31';
		$EM_Event->end_date = $new_end_date;
		
		if (strtotime($current_date) == strtotime('01.11.' . $current_year)) {
			$EM_Event->recurring_reschedule = true;
			$EM_Event->save(); 
		}	
    } 
}
add_shortcode('update_event_data', 'update_event_data_shortcode');

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer