After install the themes are not working
If you have installed the plugin through FTP and themes are not working, delete the plugin from wordpress backend and reinstall through wordpress interface as explained here.
After install the themes are not working
If you have installed the plugin through FTP and themes are not working, delete the plugin from wordpress backend and reinstall through wordpress interface as explained here.
I get the error “The package could not be installed. No valid plugins were found. Plugin install failed.” when I try to install the plugin.
Make sure that you are uploading the correct zip file to your WordPress site. Which is calendar-anything.zip. And not the whole zip file that you have downloaded from envato.
Can I hide a calendar using PHP conditions?
Yes you can by using the cmcal_show_calendar filter. For example, let’s say that you want to hide the calendar with id 23 for all not-logged-in users. To do so, just add the code below in your functions.php:
add_filter('cmcal_show_calendar', 'hide_calendars', 10, 2);
function hide_calendars($show_calendar, $calendar_id) {
if ($calendar_id == 23 && (!is_user_logged_in()))
return false;
return true;
}
Can I use my own query for a calendar?
Yes you can by using the cmcal_calendar_posts_query filter.
Let’s say that you want to show inside calendar with ID 23, all WooCommerce products that belong to the product category 35. To do so, just add the code below in your functions.php:
add_filter('cmcal_calendar_posts_query', 'calendar_return_specific_category', 10, 2);
function calendar_return_specific_category($query_args, $calendar_id) {
if ($calendar_id == 23) {
$query_args = array(
'post_type' => array('product'),
'post_status' => array('publish', 'future'),
'posts_per_page' => -1,
'fields' => "ids",
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => array('35'),
),
),
);
}
return $query_args;
}
Let’s say that you want to show every event disregarding the post status (since a plugin may use it’s own post_status).
add_filter('cmcal_calendar_posts_query', 'calendar_remove_post_status', 10, 2);
function calendar_remove_post_status($query_args, $calendar_id) {
$query_args = array(
'post_type' => array('product'),
// 'post_status' => array('publish', 'future'),
'posts_per_page' => -1,
'fields' => "ids",
);
return $query_args;
}
Let’s say that you use our events, in order to show events from a specific category (with ID 130), you can use the following code:
add_filter('cmcal_calendar_posts_query', 'calendar_return_specific_category', 10, 2);
function calendar_return_specific_category($query_args, $calendar_id) {
if ($calendar_id == 128) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'cmcal_event_category',
'field' => 'term_id',
'terms' => array('130'),
)
);
}
return $query_args;
}
Let’s say that you want your current logged in user to see the only the events published by him, you can use the following code:
add_filter('cmcal_calendar_posts_query', 'calendar_current_user_posts', 10, 2);
function calendar_current_user_posts($query_args, $calendar_id) {
$current_user_id = get_current_user_id();
$query_args['author__in'] = array($current_user_id);
return $query_args;
}
Let’s say that you want to show events with certain post statuses. In the example below we want to show the events that are published or draft.
add_filter('cmcal_calendar_posts_query', 'cmcal_calendar_posts_query_custom_statuses', 10, 2);
function cmcal_calendar_posts_query_custom_statuses($query_args, $calendar_id) {
$query_args['post_status'] = array('publish', 'draft');
return $query_args;
}
Can I set a custom date range using PHP code?
Yes you can. Here is an example where you see only events that begin 2 months from current date.
// Only show events after 2 months for current date
add_filter('cmcal_events_date_range', 'cmcal_events_date_range_custom');
function cmcal_events_date_range_custom($dates) {
$date_now = new DateTime();
//Add 2 Months to today date
$date_now->add(new DateInterval('P2M'));
//Get The first day of month
$start_date = date('Y-m-d', strtotime('first day of this month ' . $date_now->format('Y-m-d')));
$dates['min_date'] = $start_date;
$dates['max_date'] = null;
return $dates;
}
// Set the calendar default date to be movevable and 2 months after the today date
add_filter('cmcal_js_vars', 'cmcal_js_vars_custom');
function cmcal_js_vars_custom($vars) {
$date_now = new DateTime();
//Add 2 Months to today date
$date_now->add(new DateInterval('P2M'));
//Get The first day of month
$start_date = date('m/d/Y', strtotime('first day of this month ' . $date_now->format('Y-m-d')));
$vars['defaultDateMode'] = "1";
$vars['defaultDate_CertainDate'] = $start_date;
return $vars;
}
What if my custom field date is a timestamp (eg. EventOn, Toolset Types)?
Let’s say that you are adding a date custom field to your post types by using Toolset Types plugin.
This plugin has the option to input date and time at the same time.
In order for our plugin to be compatible with Toolset Types, you must add the filter below in your functions.php:
add_filter('cmcal_event_start_end_date', 'cmcal_event_start_end_date_timestamp', 10, 4);
function cmcal_event_start_end_date_timestamp($dates, $id, $EM_Event, $post_type) {
$options = CMCAL()->setup_options;
$post_types_options = $options['post_types_options'];
$post_type_options = $post_types_options[$post_type];
$start_date_meta_key = (int) get_post_meta($id, $post_type_options["start_date_meta_key"], true);
$end_date_meta_key = (int) get_post_meta($id, $post_type_options["end_date_meta_key"], true);
$start_time_meta_key = (int) get_post_meta($id, $post_type_options["start_time_meta_key"], true);
$end_time_meta_key = (int) get_post_meta($id, $post_type_options["end_time_meta_key"], true);
$dates['start_date'] = date('Y-n-j', $start_date_meta_key);
$dates['end_date'] = date('Y-n-j', $end_date_meta_key);
$dates['start_time'] = date('H:i', $start_time_meta_key);
$dates['end_time'] = date('H:i', $end_time_meta_key);
return $dates;
}
And then add you custom field (the same) in both 4 options: Start Date from Meta key, Start Time from Meta key, End Date from Meta key, End Time from Meta key.
What if my custom fields are saved in my database as UTC?
In that case, you can shift them to your local timeline by using this filter:
add_filter('cmcal_event_start_end_date', 'cmcal_fix_gtm', 10, 4);
function cmcal_fix_gtm($dates, $id, $EM_Event, $post_type) {
$dates['start_date'] = get_date_from_gmt($dates['start_date'] . " " . $dates['start_time'], 'Y-n-j');
$dates['end_date'] = get_date_from_gmt($dates['end_date'] . " " . $dates['end_time'], 'Y-n-j');
$dates['start_time'] = get_date_from_gmt($dates['start_date'] . " " . $dates['start_time'], 'H:i');
$dates['end_time'] = get_date_from_gmt($dates['end_date'] . " " . $dates['end_time'], 'H:i');
return $dates;
}
Does it work with ACF custom fields?
Yes it does work. You just to have make the correct setup.
First of all, use the ACF plugin to create the 2 date/time fileds that you will use in order to set the event start and end date/times. In our example, we will add the 2 date fields to our site’s posts, since we want to show the posts as events.
Then, in your calendar setup, set the correct date fields.
Can I add events to a calendar by using PHP?
Yes you can. You can use the following filter:
add_filter('cmcal_calendar_events', 'cmcal_calendar_events_custom', 10, 2);
function cmcal_calendar_events_custom($events, $calendar_id) {
$new_events = array(
'url' => 'http://www.test.com',
'url_new_window' => 'false',
'title' => 'My custom event',
'start' => '2019-08-29T21:00:00',
'end' => '2019-08-29T23:30:00',
);
$events[] = $new_events;
return $events;
}
Can I show only the 2 next events from the current date?
Yes you can. To do so:
add_filter('cmcal_calendar_events', 'cmcal_calendar_events_custom', 10, 2);
function cmcal_calendar_events_custom($events, $calendar_id) {
if ($calendar_id == "42") { // enter you calendar ID here
usort($events, function ($a, $b) {
return strtotime($a['start']) > strtotime($b['start']);
});
$events = array_slice($events, 0, 2);
}
return $events;
}
Can I change the date format for toolbar title?
Just add this javascript code:
function cmcal_custom_title(start, end, locale, view, calendar_id) {
if (view == "dayGridMonth")
return start.locale(locale).format("MMMM YYYY");
if (view == "dayGridDay")
return start.locale(locale).format("D MMMM YYYY");
return null;
}
To add this code you can use a simple plugin like Simple Custom CSS and JS.
How can add my custom PHP code in the event template?
Step 1:
Add the following filters in your functions.php:
add_filter('cmcal_extra_fields', 'cmcal_extra_fields_add');
function cmcal_extra_fields_add($extra_fields) {
$extra_fields[] = "my_extra";
return $extra_fields;
}
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_custom', 10, 2);
function cmcal_calendar_event_custom($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
// put your logic here
$my_logic = "ID:" . $event_id . " ";
$event_properties["my_extra"] = $my_logic; // make sure you use my_extra from before
$event->properties = $event_properties;
return $event;
}
Step 2:
Go to your calendar and in the Event settings > Templates, insert there (in the month view and/or list view) the new shortcode that has been created:
[my_extra]
Can I render the calendar in a backend page?
Yes you can. Just add the code below in your functions.php. You can see here 2 examples. In the first you add the calendar at your dashboard. At the second you add the calendar at a custom backend page.
add_action('init', 'init_Cmcal_Frontend', 10);
function init_Cmcal_Frontend() {
if (is_admin()) { // render in all backend pages
if (isset($_GET['page']) && $_GET['page'] == "customize-calendar") // do not return in customize calendar page
return;
// if ($_GET['page'] == "backend-cmcal-calendar") { // uncomment this line to render only in the desired backend page
include_once(Codemine_Calendar_PLUGIN_DIR_PATH . 'includes/frontend/class-cmcal-frontend.php');
$frontend = new Cmcal_Frontend();
$frontend->init();
add_action('admin_enqueue_scripts', array($frontend, 'calendar_register_scripts'));
// } // uncomment this line to render only in the desired backend page
}
}
////////////////////////////////////////////////////////
//
// Add the calendar as a dashboard widget
//
////////////////////////////////////////////////////////
function wpexplorer_add_dashboard_widgets() {
wp_add_dashboard_widget(
'wpexplorer_dashboard_widget', // Widget slug.
'My Custom Dashboard Widget', // Title.
'wpexplorer_dashboard_widget_function' // Display function.
);
}
add_action('wp_dashboard_setup', 'wpexplorer_add_dashboard_widgets');
function wpexplorer_dashboard_widget_function() {
echo do_shortcode('[calendar_anything id="12"]');
}
////////////////////////////////////////////////////////
//
// Add the calendar in a backend page
//
////////////////////////////////////////////////////////
//Add Sample menu page for calendar
add_action('admin_menu', 'backend_cmcal_menu');
function backend_cmcal_menu() {
add_menu_page(
__('Backend calendar page', 'my-textdomain'), __('Backend calendar menu', 'my-textdomain'), 'manage_options', 'backend-cmcal-calendar', 'backend_cmcal_menu_page_contents', 'dashicons-schedule', 3
);
}
//Backend calendar page content
function backend_cmcal_menu_page_contents() {
?>
<h1>
<?php esc_html_e('Backend calendar', 'my-textdomain'); ?>
</h1>
<?php
//Calendar Shortcode
echo do_shortcode('[calendar_anything id="12"]');
}
Is Calendar Anything compatible with My Listing theme?
Yes, it is fully compatible with My Listing theme.
To show your My Listing events in a calendar:
Can I add my own custom filter in the calendar?
Yes you can by using our filters.
Here is an example where you can add a filtering by using the WordPress post status (eg. published, draft, etc.)
// set filter dropdown
add_filter('cmcal_custom_filters', 'cmcal_custom_filters', 10);
function cmcal_custom_filters($custom_filters) {
$custom_filters[] = array(
"id" => "cmcal_post_status", // a unique ID, you will use this ID later
"values" => get_post_statuses(), // an array as seen in the comment below
);
return $custom_filters;
}
// The array added in values
//array(
// 'draft' => __('Draft'),
// 'pending' => __('Pending Review'),
// 'private' => __('Private'),
// 'publish' => __('Published'),
//);
// set the value in the event that you will use for filtering
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_post_status', 10, 2);
function cmcal_calendar_event_post_status($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
$event_properties["cmcal_post_status-ids"] = array(get_post_status($event_id)); // the ID we used previously with -ids
$event->properties = $event_properties;
return $event;
}
Now, follow the steps on our documentation section regarding filtering.
Here is an example where you can add a filtering by using an ACF custom field. Let’s suppose you have a select ACF field attached to the events with 2 simple options, Choice 1 and Choice 2. Here is the code:
// set filter dropdown
add_filter('cmcal_custom_filters', 'cmcal_custom_filters', 10);
function cmcal_custom_filters($custom_filters) {
$custom_filters[] = array(
"id" => "cmcal_acf_filter_field", // a unique ID, you will use this ID later
"values" => array(
'choice1' => __('Choice 1'),
'choice2' => __('Choice 2'),
),
);
return $custom_filters;
}
// set the value in the event that you will use for filtering
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_post_status', 10, 2);
function cmcal_calendar_event_post_status($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
$field = get_field('test_cf_select', $event_id);
$event_properties["cmcal_acf_filter_field-ids"] = $field; // the ID we used previously with -ids
$event->properties = $event_properties;
return $event;
}
Now, follow the steps on our documentation section regarding filtering.
Can I use my own conditions to colorize the event?
Yes you can by using the cmcal_calendar_event filter.
If you use ACF plugin to add a background color to your events with the ID cf_background_color, you can use the following code:
add_filter('cmcal_calendar_event', 'cmcal_calendar_set_color', 10, 2);
function cmcal_calendar_set_color($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
// enter your custom field ID below
$event_properties["backgroundColor"] = get_field('cf_background_color', $event_id);
$event->properties = $event_properties;
return $event;
}
You can change the background and text color of your events depending on post type. Use the following code:
add_filter('cmcal_calendar_event', 'cmcal_calendar_set_color', 10, 2);
function cmcal_calendar_set_color($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
switch (get_post_type($event_id)) {
case 'post-type-1':
$event_properties["backgroundColor"] = '#00c0c1';
break;
case 'post-type-2':
$event_properties["backgroundColor"] = '#00c0c1';
break;
default:
$event_properties["backgroundColor"] = '#f9f871';
$event_properties["textColor"] = '#000';
break;
}
$event->properties = $event_properties;
return $event;
}
Can I use ACF repeater fiels for my repeating events?
Yes you can. Just use the following filter:
add_filter('cmcal_calendar_events', 'cmcal_calendar_events_custom', 10, 2);
function cmcal_calendar_events_custom($events, $calendar_id) {
$repeating_events = [];
foreach ($events as $event) {
$post_id = $event["id"];
//Loop the date repeater fields
$i = 0;
while (the_repeater_field('dates_repeater', $post_id)) :
$i++;
//In this example dates from and to are datetime ACF fields
$date_from = get_sub_field('date_from', false);
$date_from = CMCAL()->utils->parseDateTime($date_from, null);
$date_to = get_sub_field('date_to', false);
$date_to = CMCAL()->utils->parseDateTime($date_to, null);
$event['start'] = $date_from->format('c');
$event['end'] = $date_to->format('c');
//Uncomment the 2 commented lines below, if you don't want the 1st repeating date to re-included
// if ($i != 1){
$repeating_events[] = $event;
// }
endwhile;
}
//Add repeating events
foreach ($repeating_events as $repeating_event) {
$events[] = $repeating_event;
}
return $events;
}
For multi-day events, can I just show a single cell?
Yes you can.
Step 1:
Add the code below inside functions.php:
add_filter('cmcal_extra_fields', 'cmcal_extra_fields_add');
function cmcal_extra_fields_add($extra_fields) {
$extra_fields[] = "date_with_range";
return $extra_fields;
}
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_custom', 10, 2);
function cmcal_calendar_event_custom($event, $calendar_id) {
if ($calendar_id == "12") { // your calendar ID here
$event_properties = $event->properties;
$format = 'Y-m-d';
$start = $event->start->format($format);
$end = $event->end->format($format);
// Format like 15 Oct
$date_with_range = date_i18n("d F", strtotime($start));
//If the event expands in more than one day
if ($start != $end) {
// Format like 15 - 18 Oct
if ($event->start->format('Y-m') == $event->end->format('Y-m')) {
$date_with_range = date_i18n("d", strtotime($start)) . ' - ' . date_i18n("d F", strtotime($end));
}
// Format like 28 Oct - 3 Nov
else {
if ($event->start->format('Y') == $event->end->format('Y')) {
$date_with_range = date_i18n("d F", strtotime($start)) . ' - ' . date_i18n("d F", strtotime($end));
} else {
$date_with_range = date_i18n("d F Y", strtotime($start)) . ' - ' . date_i18n("d F Y", strtotime($end));
}
}
//Set end date to null so that event will not expand
$event->end = null;
}
$event_properties["date_with_range"] = $date_with_range;
$event->properties = $event_properties;
}
return $event;
}
Step 2:
Go to your calendar and in the Event settings > Templates, insert there (in the month view and/or list view) the new shortcode that has been created:
[date_with_range].
Can I change the event URL link using PHP?
Yes you can by using the cmcal_event_data filter.
add_filter('cmcal_event_data', 'cmcal_event_data_custom', 10, 3);
function cmcal_event_data_custom($data, $calendar_id, $id) {
if ($calendar_id == '123') { // restrict this option for a specific calendar
$data['url'] = 'https://customurl.com/?event_id=' . $id;
$data['url_new_window'] = 'true';
}
return $data;
}
Can I disable the event link functionality based on a start and end date?
If you need to be able to prevent a link being clickable unless within a specified timeframe, just modify the code below:
add_filter('cmcal_event_data', 'cmcal_event_data_custom', 10, 3);
function cmcal_event_data_custom($data, $calendar_id, $id) {
if ($calendar_id == '128') { // restrict this option for a specific calendar
// Get start date of event
$start = CMCAL()->utils->parseDateTime($data['start'], null);
// // Get end date of event
// $end = CMCAL()->utils->parseDateTime($data['end'], null);
// Get current date
$now = new DateTime();
// If start date of event < current date remove link
if ($start < $now) { // disable links for past events
unset($data['url']);
unset($data['url_new_window']);
}
}
return $data;
}
Is it possible to adjust the order of events that start at the same time?
The default ordering of the events within the same day puts earlier events first.
If tied, it puts longer events first.
If tied, it puts all-day events first.
If still tied, orders events by title, alphabetically.
If you want to change the ordering, then you should create a custom field for the events, and set this field for the desired events by using a number (eg. 1,2,3 etc) which will define the ordering.
Here is how you can do so:
Go to Step 2.
You can do the exact same by using any custom field plugin (like eg. ACF).
Go to Step 2.
Add the code below in your functions.php:
add_action('wp_enqueue_scripts', 'cmcal_events_same_time_reorder', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_same_time_reorder', 9999);
function cmcal_events_same_time_reorder() {
$output = 'document.addEventListener("DOMContentLoaded", function () {
cmca_calendars[12].setOption("eventOrder", ["start", "event_custom_order", "title"]);
})';
wp_add_inline_script('codemine-calendar-js', $output, 'after');
}
Shortcode for showing the next instance of a repeating event
Add the code below in your functions.php:
add_filter('cmcal_calendar_posts_query', 'calendar_return_specific_category', 10, 2);
function calendar_return_specific_category($query_args, $calendar_id) {
if ($calendar_id == 'single_post') {
$query_args["post__in"] = array(get_the_ID());
}
return $query_args;
}
add_shortcode('cmcal_next_event_date', 'cmcal_next_event_date_shortcode');
function cmcal_next_event_date_shortcode() {
$output = '';
$date_now = new Datetime();
$events = CMCAL()->dal->get_events(null, null, null, "single_post", false);
if (empty($events))
return '';
usort($events, 'cmcal_events_sortBy_start_date');
$next_event = null;
foreach ($events as $event) {
$current_diff = strtotime($event['end']) - $date_now->getTimestamp();
if ($current_diff > 0) {
$next_event = $event;
break;
}
}
if (!empty($next_event)) {
$next_date_start_date_formatted = date_i18n('D, d. M H:i', strtotime($next_event['start']));
$next_date_end_time_formatted = date_i18n('H:i', strtotime($next_event['end']));
$output .= $next_date_start_date_formatted . ' - ' . $next_date_end_time_formatted;
}
return $output;
}
add_shortcode('cmcal_event_future_dates', 'cmcal_event_future_dates_shortcode');
function cmcal_event_future_dates_shortcode($atts) {
$limit = isset($atts["limit"]) ? $atts["limit"] : null;
$limit = is_numeric($limit) ? $limit : null;
$output = '';
$date_now = new Datetime();
$events = CMCAL()->dal->get_events(null, null, null, "single_post", false);
if (empty($events))
return '';
usort($events, 'cmcal_events_sortBy_start_date');
$i = 0;
foreach ($events as $event) {
$current_diff = strtotime($event['end']) - $date_now->getTimestamp();
if ($current_diff > 0) {
$i++;
$next_date_start_date_formatted = date_i18n('D, d. M H:i', strtotime($event['start']));
$next_date_end_time_formatted = date_i18n('H:i', strtotime($event['end']));
$output .= $next_date_start_date_formatted . ' - ' . $next_date_end_time_formatted . '<br />';
if (!empty($limit) && $limit == $i) {
break;
}
}
}
return $output;
}
function cmcal_events_sortBy_start_date($a, $b) {
return strtotime($a['start']) - strtotime($b['start']);
}
To show next instance of the repeating event, you can use the code below:
[cmcal_next_event_date]
To show all future instances of the repeating event, you can use the code below:
[cmcal_event_future_dates]
To show, eg. 4 future instances of the repeating event, you can use the code below:
[cmcal_event_future_dates limit="4"]
How can I add extra iCal fields?
Let’s say that you want to show in iCal feed the location, which in our case, we get it from an ACF field.
Insert the code below in your functions.php:
add_filter('cmcal_ical_event', 'cmcal_ical_event_add_location', 10, 3);
function cmcal_ical_event_add_location($ical_event, $event_id, $calendar_id) {
$ical_event["LOCATION"] = get_field("location", $event_id);
return $ical_event;
}
Is there any way to connect the start date to two different meta keys?
You can add the code below (and customize according to your needs):
add_filter('cmcal_calendar_events', 'cmcal_calendar_events_with_two_dates', 10, 2);
function cmcal_calendar_events_with_two_dates($events, $calendar_id) {
$repeating_events = [];
foreach ($events as $event) {
$post_id = $event["id"];
// Our meta keys for date 2
$date_start_2 = get_post_meta($post_id, 'date_start_2', true);
$date_end_2 = get_post_meta($post_id, 'date_end_2', true);
if (!empty($date_start_2)) {
$date_start_2_datetime = CMCAL()->utils->parseDateTime($date_start_2, null);
$event['start'] = $date_start_2_datetime->format('c');
if (!empty($date_end_2)) {
$date_end_2_datetime = CMCAL()->utils->parseDateTime($date_end_2, null);
$event['end'] = $date_end_2_datetime->format('c');
} else {
//Set end date == start date
$event['end'] = $event['start'];
}
$events[] = $event;
}
}
return $events;
}
How can I include repeating events in google calendar?
Add this in your functions.php:
add_filter('cmcal_ical_event', 'cmcal_ical_event_fix_repeating_id', 10, 3);
function cmcal_ical_event_fix_repeating_id($ical_event, $event_id, $calendar_id) {
$ical_event["UID"] = $ical_event["UID"] . '-' . $ical_event["DTSTART"];
return $ical_event;
}
In minimal month, can I redirect the user when he clicks a day to a specific URL?
1. Go to your calendar Customize Calendar Appearance -> Themes and choose a Minimal theme.
2. Go to your calendar Customize Calendar Appearance -> General Settings -> Settings -> Enable Navigation Links and set it to Disabled.
3. Add the code below in your functions.php file:
add_action('wp_enqueue_scripts', 'cmcal_events_same_time_reorder', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_same_time_reorder', 9999);
function cmcal_events_same_time_reorder() {
$output = 'document.addEventListener("DOMContentLoaded", function () {
//128 is the acalendar id
cmca_calendars[128].on("dateClick", function(info) {
//check if date has events
if(jQuery(info.dayEl).hasClass("has-events")){
window.location.href = "https://www.mywebsite.com/" + moment(info.date).utc().format("YYYY/MM/DD");
}
});
})';
wp_add_inline_script('codemine-calendar-js', $output, 'after');
}
4. Add the code below in your style.css file
.cmcal-calendar-128 td.has-events,
.cmcal-calendar-128 td.has-events .fc-day-number{
cursor:pointer;
}
In our example 128 is the calendar id
Display time range + all day in event template
Want to create your own time range and render it in the event template?
Step 1:
Add the code below inside functions.php:
add_filter('cmcal_extra_fields', 'cmcal_extra_fields_time_range');
function cmcal_extra_fields_time_range($extra_fields) {
$extra_fields[] = "time_with_range";
return $extra_fields;
}
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_field_time_range', 1, 2);
function cmcal_calendar_event_field_time_range($event, $calendar_id) {
if ($calendar_id == "128") {
$event_properties = $event->properties;
if ($event->allDay) {
$time_with_range = "ALL DAY";
} else {
$format = 'Y-m-d H:i';
$start = $event->start->format($format);
$end = $event->end->format($format);
$time_with_range = date_i18n("H:i", strtotime($start)) . ' - ' . date_i18n("H:i", strtotime($end));
}
$event_properties["time_with_range"] = $time_with_range;
$event->properties = $event_properties;
}
return $event;
}
Step 2:
Go to your calendar and in the Event settings > Templates, insert there (in the month view and/or list view) the new shortcode that has been created:
[time_with_range].
Can I add a filter for the post types in my calendar?
Yes you can. Add this in your functions.php. This is useful for calendars that contain more then one custom post types.
// set filter dropdown
add_filter('cmcal_custom_filters', 'cmcal_custom_filters_post_type', 10);
function cmcal_custom_filters_post_type($custom_filters) {
//Array with post types
$post_types = array(
'post' => __('Post'),
'product' => __('Product'),
);
$custom_filters[] = array(
"id" => "cmcal_post_type", // a unique ID, you will use this ID later
"values" => $post_types,
);
return $custom_filters;
}
// set the value in the event that you will use for filtering
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_post_type', 10, 2);
function cmcal_calendar_event_post_type($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
$event_properties["cmcal_post_type-ids"] = array(get_post_type($event_id)); // the ID we used previously with -ids
$event->properties = $event_properties;
return $event;
}
Can I change the format on date and time picker on the backend?
Yes you can by using the following filters:
add_filter('cmcal_datepicker_attributes', 'cmcal_datepicker_attributes_custom', 10);
function cmcal_datepicker_attributes_custom($attributes) {
$attributes = array(
'data-datepicker' => json_encode(
array(
'firstDay' => 0,
)
)
);
return $attributes;
}
add_filter('cmcal_timepicker_time_format', 'cmcal_timepicker_time_format_custom', 10);
function cmcal_timepicker_time_format_custom($time_format) {
return 'h:i A';
}
How can I show different view for mobile if i have multiple-view buttons in the toolbar?
In this case, you should show all your view-buttons (desktop and mobile) to your calendar and use CSS media queries to show the respective buttons.
1) In section Toolbar Settings->Buttons Displayed add all the buttons you want.
2) In section Custom CSS you can add rules like these:
@media screen and (min-width: 1401px) {
{calendar_id_class} .fc-listMonth-button,
{calendar_id_class} .fc-listWeek-button{
display: none !important;
}
}
@media screen and (max-width: 1400px) {
{calendar_id_class} .fc-dayGridMonth-button,
{calendar_id_class} .fc-dayGridWeek-button{
display: none !important;
}
}
3) In section Responsive Settings->Responsive Views you set Basic Week Responsive View->List Week.
Can I customize the event dates through PHP?
Let’s say that you have ACF fields for you date fields. Yes you can by using the filter below:
add_filter('cmcal_event_start_end_date', 'cmcal_event_start_end_date_timestamp', 10, 4);
function cmcal_event_start_end_date_timestamp($dates, $id, $EM_Event, $post_type) {
$options = CMCAL()->setup_options;
$post_types_options = $options['post_types_options'];
$post_type_options = $post_types_options[$post_type];
// Get meta_keys stored in database
$start_date_meta_key = get_post_meta($id, $post_type_options["start_date_meta_key"], true);
$end_date_meta_key = get_post_meta($id, $post_type_options["end_date_meta_key"], true);
$start_time_meta_key = get_post_meta($id, $post_type_options["start_time_meta_key"], true);
$end_time_meta_key = get_post_meta($id, $post_type_options["end_time_meta_key"], true);
//////////////////////////////////////////////////
//put your logic here
//////////////////////////////////////////////////
//Convert to timestamp
$start_date_meta_key = strtotime($start_date_meta_key);
$end_date_meta_key = strtotime($end_date_meta_key);
$start_time_meta_key = strtotime($start_time_meta_key);
$end_time_meta_key = strtotime($end_time_meta_key);
// Set the date values
$dates['start_date'] = date('Y-n-j', $start_date_meta_key);
$dates['end_date'] = date('Y-n-j', $end_date_meta_key);
$dates['start_time'] = date('H:i', $start_time_meta_key);
$dates['end_time'] = date('H:i', $end_time_meta_key);
return $dates;
}
Can I show the date range in the event?
Yes you can by adding the code below inside your functions.php.
add_filter('cmcal_extra_fields', 'cmcal_extra_fields_add');
function cmcal_extra_fields_add($extra_fields) {
$extra_fields[] = "date_with_range";
return $extra_fields;
}
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_custom', 10, 2);
function cmcal_calendar_event_custom($event, $calendar_id) {
$event_properties = $event->properties;
$format = 'Y-m-d';
$start = $event->start->format($format);
$end = $event->end->format($format);
// Format like 15 Oct
$date_with_range = date_i18n("d F", strtotime($start));
//If the event expands in more than one day
if ($start != $end) {
// Format like 15 - 18 Oct
if ($event->start->format('Y-m') == $event->end->format('Y-m')) {
$date_with_range = date_i18n("d", strtotime($start)) . ' - ' . date_i18n("d F", strtotime($end));
}
// Format like 28 Oct - 3 Nov
else {
$date_with_range = date_i18n("d F", strtotime($start)) . ' - ' . date_i18n("d F", strtotime($end));
}
// //Set end date to null so that event will not expand
// $event->end = null;
}
$event_properties["date_with_range"] = $date_with_range;
$event->properties = $event_properties;
return $event;
}
Can I use extrenal HTML elements as filters for my calendar?
Say for example that you want to create a multiselect with select2 and use it as a filter for your calendar. Let’s say that you have the following multiselect somewhere in your page where the calendar is (eg. above the calendar):
<select name="cmcal-custom-filter" multiple="multiple">
<option value=""></option>
<option value="129">Category 1</option>
<option value="130">Category 2</option>
<option value="165">Category 3</option>
</select>
Then add this code in your functions.php:
add_action('wp_enqueue_scripts', 'cmcal_events_custom_filter_select2', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_custom_filter_select2', 9999);
add_action('wp_enqueue_scripts', 'cmcal_events_custom_filter_select2', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_custom_filter_select2', 9999);
function cmcal_events_custom_filter_select2() {
$output = 'document.addEventListener("DOMContentLoaded", function () {
// Select2
jQuery("select[name=cmcal-custom-filter]").select2();
// Filter calendar on change selected value
jQuery("select[name=cmcal-custom-filter]").on("change", function (e) {
// 128 is the calendar ID
cmcal_filterCalendar(jQuery("#cmcal_calendar_128"));
});
jQuery(document).on("cmcal_event_visible", function (e, data) {
var calendar = data.calendar;
// 128 is the calendar ID
if(calendar.attr("data-cmcal-id") == "128"){
var event = data.event;
var filter_box = jQuery("select[name=cmcal-custom-filter]");
if (filter_box.length > 0) {
var filter_vals = filter_box.val();
//Nothing selected -> Show all events
if (filter_vals.length == 0){
return true;
}
// Get Event taxonomyy ids
var event_tax_ids = event.extendedProps["cmcal_event_category-ids"]
//Event category is not set -> Hide event
if (typeof(event_tax_ids) == "undefined"){
return false;
}
// For multi select, check each value
for (i = 0; i < filter_vals.length; i++) {
filter_val = filter_vals[i];
var filter_val_converted = isNaN(parseInt(filter_val)) ? filter_val : parseInt(filter_val);
if (filter_val && event_tax_ids.includes(filter_val_converted)){
return true;
}
}
}
return false;
}
});
})';
wp_add_inline_script('codemine-calendar-js', $output, 'after');
}
Side-by-side calendars and toolbar on the second calendar
If you add a toolbar on your second calendar, then in order to change the first calendar when you naviagate through it, just add the following code in your functions.php.
Make sure that your replace 71 with your second calendar ID and 70 with your first calendar ID.
add_action('wp_enqueue_scripts', 'cmcal_modify_calendars', 9999);
add_action('admin_enqueue_scripts', 'cmcal_modify_calendars', 9999);
function cmcal_modify_calendars() {
$output ='
document.addEventListener("DOMContentLoaded", function () {
// 71 is the id of the list view calendar
jQuery(document).on("cmcal_after_datesRender", function (e, data) {
if(data.calendar.attr("data-cmcal-id") == "71"){
// Set selected date to navigation calendar. 70 is the id of the navigation calendar
jQuery("#cmcal_calendar_70 .fc-bg td").removeClass("selected");
var currentStart = data.info.view.currentStart;
if(typeof(cmca_calendars[70]) != "undefined"){
cmca_calendars[70].gotoDate( currentStart );
}
var currentStart_striped = cmcal_get_date_without_TimezoneOffset(data.info.view.currentStart);
var currentStart_formatted = moment(currentStart_striped).format("YYYY-MM-DD");
jQuery("#cmcal_calendar_70 .fc-bg td[data-date=" + currentStart_formatted + "]").addClass("selected");
}
// When we change the month of the navigation calendar, the list view will navigate to the first day of the month
if(data.calendar.attr("data-cmcal-id") == "70"){
// Set selected date to list calendar.
var currentStart = data.info.view.currentStart;
if(typeof(cmca_calendars[71]) != "undefined"){
cmca_calendars[71].gotoDate( currentStart );
}
}
});
});
';
wp_add_inline_script('codemine-calendar-js', $output, 'before');
}
Set calendar’s custom default date with PHP code
You can add a similar filter in your functions.php:
add_filter('cmcal_js_vars', 'cmcal_js_vars_custom', 10, 2);
function cmcal_js_vars_custom($vars, $calendar_id) {
$date_now = new DateTime();
$start_date = $defaultDateMode = null;
//128 is the calendar ID
if ($calendar_id == "128") {
//set start date the first day of the previews month
$start_date = date('m/d/Y', strtotime('first day of -1 month'));
}
if (!empty($start_date)) {
$vars['defaultDateMode'] = "1";
$vars['defaultDate_CertainDate'] = $start_date;
}
return $vars;
}
Can I change the view of a calendar with PHP code?
Yes you can by adding some PHP code in your functions.php. In the example below, we change the calendar with ID 128 view to listYear, only to page with ID 1127:
add_filter('cmcal_js_vars', 'cmcal_js_vars_custom', 10, 2);
function cmcal_js_vars_custom($vars, $calendar_id) {
//128 is the calendar ID
if ($calendar_id == "128") {
//1127 is the page or post ID
if (is_page("1127") || is_single("1127")) {
// Set default View
// dayGridMonth -> Month
// dayGridWeek -> Basic Week
// dayGridDay -> Basic Day
// timeGridWeek -> Agenda Week
// timeGridDay -> Agenda Day
// listYear -> List Year
// listMonth -> List Month
// listWeek -> List Week
// listDay -> List Day
// listDuration -> List Duration
$vars['defaultView'] = "listYear";
}
}
return $vars;
}
Can I display the count of events on the days/cells of a month view for a minimal theme?
Yes you can.
Step 1:
Add the following code inside functions.php.
add_action('wp_enqueue_scripts', 'cmcal_events_counter', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_counter', 9999);
function cmcal_events_counter() {
$output ='
document.addEventListener("DOMContentLoaded", function () {
// 71 is the id of the list view calendar
jQuery(document).on("cmcal_event_visible", function (e, data) {
if(data.calendar.attr("data-cmcal-id") == "128") {
var view = data.view.type;
if (view == "dayGridMonth") {
var event_days = cmcal_enumerateDaysBetweenDates(data.event.start, data.event.end, data.view.activeStart, data.view.activeEnd);
var event_days_length = event_days.length;
var event_day;
var fc_day_bg;
var count_events = 0;
for (i = 0; i < event_days_length; i++) {
event_day = event_days[i];
fc_day_bg = data.calendar.find(".fc-bg .fc-day[data-date=" + event_day + "]");
fc_day_bg.each(function( index ) {
var count_events = jQuery( this ).attr("count-events");
if(typeof(count_events)== "undefined"){
count_events = 0;
}else{
count_events = parseInt(count_events);
}
count_events = count_events + 1;
fc_day_bg.attr("count-events", count_events);
});
}
}
}
});
});
';
wp_add_inline_script('codemine-calendar-js', $output, 'before');
}
Step 2:
Open your calendar setup and insert in the Custom CSS the following styling rules.
{calendar_id_class} [count-events]{
position: relative;
}
{calendar_id_class} [count-events]::before {
content: attr(count-events);
display: block;
position: absolute;
top: 10px;
right: 10px;
background-color: black;
color: white;
border-radius: 50%;
width: 20px;
height: 20px;
}
Miminal month colorize day and send to event scenario
Let’s say that I have made a calendar with the theme Month Minimal Pink. How do I make it so that when I click it it sends me directly to the permalink? I only have one event per date so I don’t need the list. And also how do I get the event category colour to be displayed in the calendar and not a fixed colour?
add_action('wp_enqueue_scripts', 'cmcal_events_minimal', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_minimal', 9999);
function cmcal_events_minimal() {
$output ='
document.addEventListener("DOMContentLoaded", function () {
// 128 is the id of the list view calendar
jQuery(document).on("cmcal_event_visible", function (e, data) {
if(data.calendar.attr("data-cmcal-id") == "128") {
var view = data.view.type;
if (view == "dayGridMonth") {
var event_days = cmcal_enumerateDaysBetweenDates(data.event.start, data.event.end, data.view.activeStart, data.view.activeEnd);
var event_days_length = event_days.length;
var event_day;
var fc_day_bg;
var count_events = 0;
for (i = 0; i < event_days_length; i++) {
event_day = event_days[i];
fc_day_bg = data.calendar.find(".fc-content-skeleton .fc-day-top[data-date=" + event_day + "] a.fc-day-number");
fc_day_bg.each(function( index ) {
jQuery(this).attr("href", data.event.url);
jQuery(this).attr("style", "background-color: " + data.event.backgroundColor +" !important");
jQuery(this).attr("data-goto", "");
});
}
}
}
});
});
';
wp_add_inline_script('codemine-calendar-js', $output, 'before');
}
Can I show WooCommerce orders in a calendar?
Yes you can by add the filters below in your functions.php:
add_filter('cmcal_calendar_posts_query', 'calendar_return_all_order_statuses', 10, 2);
function calendar_return_all_order_statuses($query_args, $calendar_id) {
if ($calendar_id == '128') {// restrict this option for a specific calendar
// if (($calendar_id == '128') || ($calendar_id == '130')) { // restrict this option for 2 calendars
$query_args["post_status"] = wc_get_order_statuses() ; // get all order statuses
// $query_args["post_status"] = array('wc-processing', 'wc-completed'); // get only processing and completed
}
return $query_args;
}
add_filter('cmcal_event_start_end_date', 'cmcal_event_order_get_date_created', 10, 4);
function cmcal_event_order_get_date_created($dates, $id, $EM_Event, $post_type) {
if($post_type == 'shop_order'){
$order = wc_get_order( $id );
$date_created = $order->get_date_created();
$dates['start_date'] = $dates['end_date'] = $date_created->format('Y-n-j');
$dates['start_time'] = $dates['end_time'] = $date_created->format('H:i');
}
return $dates;
}
add_filter('cmcal_event_data', 'cmcal_event_data_custom', 10, 3);
function cmcal_event_data_custom($data, $calendar_id, $id) {
if ($calendar_id == '128') {
$order = wc_get_order( $id );
$data['url'] = $order->get_edit_order_url();
}
return $data;
}
Can I display the same post in 2 different calendars depending on 2 different ACF fields?
To do so you can add the code below in functions.php and tweek it accordingly:
add_filter('cmcal_event_start_end_date', 'cmcal_event_start_end_date_custom', 10, 5);
function cmcal_event_start_end_date_custom($dates, $id, $EM_Event, $post_type , $calendar_id) {
if($calendar_id == "131"){
$start_date_meta_key = get_post_meta($id, "start_date_2", true);
$end_date_meta_key = get_post_meta($id, "end_date_2", true);
$start_time_meta_key = get_post_meta($id, "start_time_2", true);
$end_time_meta_key = get_post_meta($id, "end_time_2", true);
//Convert to timestamp
$start_date_meta_key = strtotime($start_date_meta_key);
$end_date_meta_key = strtotime($end_date_meta_key);
$start_time_meta_key = strtotime($start_time_meta_key);
$end_time_meta_key = strtotime($end_time_meta_key);
// Set the date values
$dates['start_date'] = date('Y-n-j', $start_date_meta_key);
$dates['end_date'] = date('Y-n-j', $end_date_meta_key);
$dates['start_time'] = date('H:i', $start_time_meta_key);
$dates['end_time'] = date('H:i', $end_time_meta_key);
}
return $dates;
}
Can I change First Week Day with PHP?
Yes you can by adding the following code inside your functions.php:
add_filter('cmcal_js_vars', 'cmcal_js_vars_custom');
function cmcal_js_vars_custom($vars) {
//Get numeric representation of the day (0 for Sunday, 6 for Saturday)
$today_number = date('w');
//Get numeric representation of yesterday
$yesterday_number = $today_number == 0 ? 6 : $today_number - 1;
//Set week firstDay
$vars['firstDay'] = $yesterday_number ;
return $vars;
}
How can i add the elementor content in the event template?
Step 1:
Add the following filters in your functions.php:
add_filter('cmcal_extra_fields', 'cmcal_extra_fields_add');
function cmcal_extra_fields_add($extra_fields) {
$extra_fields[] = "elementor_content";
return $extra_fields;
}
add_filter('cmcal_calendar_event', 'cmcal_calendar_event_custom', 10, 2);
function cmcal_calendar_event_custom($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
$contentElementor = "";
if (class_exists("\\Elementor\\Plugin")) {
$post_ID = 124;
$pluginElementor = \Elementor\Plugin::instance();
$contentElementor = $pluginElementor->frontend->get_builder_content($event_id);
}
$event_properties["elementor_content"] = $contentElementor;
$event->properties = $event_properties;
return $event;
}
Step 2:
Go to your calendar and in the Event settings > Templates, insert there (in the month view and/or list view) the new shortcode that has been created:
[elementor_content]
Can I use ACF repeater field for main and repeating dates + description?
Yes you can. Just use the following filter:
add_filter('cmcal_event_start_end_date', 'cmcal_event_start_end_date_repeater', 10, 4);
function cmcal_event_start_end_date_repeater($dates, $id, $EM_Event, $post_type) {
$date_from = null;
$i = 0;
while (the_repeater_field('dates_repeater', $id)) :
if($i == 0){
$date_from = get_sub_field('date_from', false);
$date_from = strtotime($date_from);
$date_from_time = get_sub_field('date_from_time', false);
$date_to = get_sub_field('date_to', false);
$date_to = strtotime($date_to);
$date_to_time = get_sub_field('date_to_time', false);
}
$i++;
endwhile;
$dates['start_date'] = empty($date_from) ? null : date('Y-n-j', $date_from);
$dates['start_time'] = empty($date_from_time) ? '00:00' : $date_from_time;
////Use this code for datetime Fields
//$dates['start_time'] = empty($date_from) ? '00:00' : date('H:i', $date_from);
$dates['end_date'] = empty($date_to) ? null : date('Y-n-j', $date_to);
$dates['end_time'] = empty($date_to_time) ? '00:00' : $date_to_time;
////Use this code for datetime Fields
//$dates['end_time'] = empty($date_to) ? '00:00' : date('H:i', $date_to);
return $dates;
}
add_filter('cmcal_calendar_events', 'cmcal_calendar_events_custom', 10, 2);
function cmcal_calendar_events_custom($events, $calendar_id) {
$repeating_events = [];
$j = 0;
foreach ($events as $event) {
$post_id = $event["id"];
//Loop the date repeater fields
$i = 0;
while (the_repeater_field('dates_repeater', $post_id)) :
$i++;
$date_from = get_sub_field('date_from', false);
$date_from = CMCAL()->utils->parseDateTime($date_from, null);
$date_from_time = get_sub_field('date_from_time', false);
////Use this code for datetime Fields
//$date_from_time = $date_from->format('H:i');
$event['start'] = $date_from->format('Y-m-d') . 'T' . $date_from_time;
$date_to = get_sub_field('date_to', false);
$date_to = CMCAL()->utils->parseDateTime($date_to, null);
$date_to_time = get_sub_field('date_to_time', false);
////Use this code for datetime Fields
//$date_to_time = $date_to->format('H:i');
$event['end'] = $date_to->format('Y-m-d') . 'T' . $date_to_time;
// description is a field inside the repeater
$description = get_sub_field('description', false);
if ($i != 1){
$event['description'] = $description;
$repeating_events[] = $event;
}else{
$events[$j]['description'] = $description;
}
endwhile;
$j++;
}
//Add repeating events
foreach ($repeating_events as $repeating_event) {
$events[] = $repeating_event;
}
return $events;
}
add_filter('cmcal_extra_fields', 'cmcal_extra_fields_add_description');
function cmcal_extra_fields_add_description($extra_fields) {
$extra_fields[] = "description";
return $extra_fields;
}
Can i change the First Week Day according to datepicker?
Yes you can. Just add the code below in your functions.php:
add_action('wp_enqueue_scripts', 'cmcal_week_date_navigate', 9999);
add_action('admin_enqueue_scripts', 'cmcal_week_date_navigate', 9999);
function cmcal_week_date_navigate() {
$output ='
document.addEventListener("DOMContentLoaded", function () {
// enter you calendar ID here
var calendar_id = "128";
jQuery("input[name=cmcal-date-navigator-" + calendar_id + "]").on("change", function () {
var date = jQuery(this).datepicker("getDate");
var options = cmca_calendars[calendar_id];
if (date == null)
firstDay = cmca.getOption("firstDay");
else
firstDay = moment(date).day();
cmca_calendars[calendar_id].setOption("firstDay", firstDay);
});
});
';
wp_add_inline_script('codemine-calendar-js', $output, 'after');
}
Get Events with WP_Query, order by our Custom Fields
Let’s say that you want to get events using WP_Query. If you are using our Custom Fields and you want to get future events ordered by date you can use the code below:
$post_type ='cmcal_event';
$start_date = 'codemine_event_' . $post_type . '_date';
$start_time = 'codemine_event_' . $post_type . '_start_time';
$query = new WP_Query(
[
'post_type' => $post_type,
'numberposts' => -1,
'orderby' => array(
'event_start_date_clause' => 'ASC',
'event_start_time_clause' => 'ASC',
),
'meta_query' => [
'relation' => 'OR',
'event_start_date_clause' => array(
'key' => $start_date,
'value' => date("Y-m-d"),
'type' => 'DATE',
'compare' => '>='
),
'event_start_time_clause' => array(
'key' => $start_time,
'value' => '1000-1-1',
'type' => 'DATE',
'compare' => '!='
),
],
// Use this if you want to filter by taxonomy
'tax_query' => [
[
'taxonomy' => 'cmcal_event_category',
'field' => 'slug',
'terms' => 'category-1'
]
]
]
);
$Events = $query->posts;
Shortcode for showing the next event of a calendar
Add the code below in your functions.php:
add_shortcode('cmcal_next_event', 'cmcal_next_event_shortcode');
function cmcal_next_event_shortcode($atts)
{
if (!isset($atts["id"])) {
return '';
}
$calendar_id = $atts["id"];
$output = '';
$date_now = new Datetime();
$events = CMCAL()->dal->get_events(null, null, null, $calendar_id, false);
if (empty($events))
return '';
usort($events, 'cmcal_events_sortBy_start_date');
$next_event = null;
foreach ($events as $event) {
$current_diff = strtotime($event['end']) - $date_now->getTimestamp();
if ($current_diff > 0) {
$next_event = $event;
break;
}
}
if (!empty($next_event)) {
$event_id = $next_event['id'];
$title = get_the_title($event_id);
$thumbnail = get_the_post_thumbnail($event_id);
$permalink = get_permalink($event_id);
$next_date_start_date_formatted = date_i18n('D, d. M H:i', strtotime($next_event['start']));
$next_date_end_time_formatted = date_i18n('H:i', strtotime($next_event['end']));
$date_time_from_to = $next_date_start_date_formatted . ' - ' . $next_date_end_time_formatted;
$output .= '<div class="cmcal_next_event">';
$output .= '<a href="' . $permalink . '">';
$output .= '<div class="thumbnail">' . $thumbnail . '</div>';
$output .= '<div class="title">' . $title . '</div>';
$output .= '<div class="date">' . $date_time_from_to . '</div>';
$output .= '</a>';
$output .= '</div>';
}
return $output;
}
function cmcal_events_sortBy_start_date($a, $b)
{
return strtotime($a['start']) - strtotime($b['start']);
}
Then you can use the shortcode below:
[cmcal_next_event id="128"]
where 12 is your calendar id
Can I remove Event Click Options meta box from post admin page?
Yes you can. Just add the code below in your functions.php. Make sure that you change the $post_type variable so that it is the one you use for events.
add_action('cmb2_after_init', 'remove_click_options_metabox');
function remove_click_options_metabox()
{
$post_type = "cmcal_event";
$prefix = 'codemine_event_' . $post_type . '_';
$cmb = cmb2_get_metabox($prefix . "event_metaboxes"); //print_r($cmb);
$cmb->remove_field($prefix . 'click_options');
$cmb->remove_field($prefix . 'action_on_click');
$cmb->remove_field($prefix . 'custom_url');
$cmb->remove_field($prefix . 'url_new_window');
}
Can I change the data of a shortcode in event template using php
Yes you can by using the cmcal_event_data filter. Let’s say for example that you want to display a custom field with time format. The time field is probably stored in the database and displayed as Hours:Minutes:Seconds. But you will probably want to display only Hours:Minutes. You can use the code below.
add_filter('cmcal_event_data', 'cmcal_event_data_custom', 10, 3);
function cmcal_event_data_custom($data, $calendar_id, $id) {
if ($calendar_id == '128') { // restrict this option for a specific calendar
if (isset($data['start_time_custom']) && !empty($data['start_time_custom'])) {
$data['start_time_custom'] = date("H:i", strtotime($data['start_time_custom']));
}
}
return $data;
}
Shortcode for single event page when using plugin’s date custom fields
Add the code below in your functions.php:
add_shortcode('cmcal_event_date', 'cmcal_event_date_shortcode');
function cmcal_event_date_shortcode() {
$id = get_the_ID();
$prefix = 'codemine_event_';
// Change this if you are using another post type
$post_type = 'cmcal_event';
$start_date_meta_key = strtotime(get_post_meta($id, $prefix . $post_type . "_date", true));
$end_date_meta_key = strtotime(get_post_meta($id, $prefix . $post_type . "_end_date", true));
$start_time_meta_key = strtotime(get_post_meta($id, $prefix . $post_type . "_start_time", true));
$end_time_meta_key = strtotime(get_post_meta($id, $prefix . $post_type . "_end_time", true));
$start_date = date('d/m/Y', $start_date_meta_key);
$end_date = date('d/m/Y', $end_date_meta_key);
$start_time = date('H:i', $start_time_meta_key);
$end_time = date('H:i', $end_time_meta_key);
return $start_date . ' ' . $start_time . ' - ' . $end_date . ' ' . $end_time;
}
Use the shortcode below:
[cmcal_event_date]
Agenda View – Show All Day Slot
This feature is no longer available as there is a bug with fullcalendar end date.
If you want to use it, keep in mind that the end date is wrong by one day. So for example if you have an All day event from 3/21/2024 to 3/22/2024 you will have to set it up from 3/21/2024 to 3/23/2024 in order to expand 2 days.
Moreover you will have to add the code below in your functions.php:
add_filter('cmcal_calendar_events', 'cmcal_calendar_events_all_day_agenda', 10, 2);
function cmcal_calendar_events_all_day_agenda($events, $calendar_id) {
$i = 0;
foreach ($events as $event) {
if(isset($event['is_allDay'])) {
$events[$i]['allDay'] = $events[$i]['is_allDay'];
}
}
$i++;
return $events;
}
Show today’s events in Elementor’s Loop Carousel
First of all go to loop carousel option “query ID” and set a unique id, for example “codemine_events”.
Then add the following code to your functions.php:
add_action( 'elementor/frontend/widget/before_render', 'loop_carousel_codemine_events' );
function loop_carousel_codemine_events( $element ) {
$widget_name = $element->get_name();
if($widget_name == "loop-carousel"){
$settings = $element->get_settings();
// 'codemine_events' is the query ID added in your loop carousel
if($settings["post_query_query_id"] == 'codemine_events'){
$today = new DateTime(date('Y-m-d'));
$events = CMCAL()->dal->get_events($today, $today, null, null , false);
$events_ids = array_column($events, 'id');
add_action('elementor/query/codemine_events',
function($query) use ($events_ids) {
$query->set( 'post__in', $events_ids );
});
}
}
}
Can I chage the language of the calendar?
By default the language of the calendar follows the language you have set up in WordPress. If you want to change the language just add the code below in your functions.php. Make sure you change the language code according to your needs. Code:
add_filter('cmcal_js_vars', 'cmcal_js_vars_custom', 10);
function cmcal_js_vars_custom($cmcal_js_vars) {
$cmcal_js_vars['language_code'] = 'fr-FR';
return $cmcal_js_vars;
}
Troubleshooting WPML
If your calendars and events aren’t translatable, please follow these steps:
1. Go to WPML > Settings >Taxonomies Translation and make sure that Calendars (cmcal_calendar) are set to Not translatable.
2. Go to WPML > Settings >Custom Fields Translation and make sure that all codemine_event_ fields are set to Copy.
3. Make sure that you use the side-by-side translator of WPML when you translate to other languages. If you click the gear icon or pencil for the translation and see the wordpress environment, open the page in the original language and click save.
This author provides limited support for this item through this item's comments.
View the item support policy
We'd like to ask you a few questions to help improve CodeCanyon.