My Calendar – API

The My Calendar exports API is enabled at My Calendar > Settings > General. This API allows you to generate a CSV, JSON, or iCal formatted export of My Calendar event data.

My Calendar > Settings > General

The API is not enabled by default. Once enabled, you can access it using URL parameters on your site:

http://www.example.com/?my-calendar-api=json&from=2021-02-01&to=2022-01-31

The my-calendar-api parameter is used to set the export format, and accepts json, csv, and ical as options.

Parameters

  • my-calendar-api: format to return, ‘json’, ‘csv’, ‘ical’
  • from: starting date to retrieve, YYYY-MM-DD (default: current date.)
  • to: end date to retrieve, YYYY-MM-DD (default: 7 days from today.)
  • mcat: Category ID to limit by.
  • ltype: Location type to restrict to (keywords: ‘name’, ‘city’, ‘state’, ‘zip’, ‘country’, ‘region’)
  • lvalue: Location value to match against location field type
  • author: Events by author ID
  • host: Events by host ID.
  • search: text search query terms.

Private events are automatically excluded from exports.

Once enabled, the export API is public by default. You can restrict access to the API using your own program logic using the filter mc_api_key.

/**
 * Check for and validate access to the My Calendar exports API.
 *
 * @return bool False to block; true to allow.
 */
function your_api_key() {
	$valid = false;
	// This example assumes the addition of an additional request parameter. However, any logic could be used here.
	if ( isset( $_REQUEST['mc_api_key'] ) ) {
		$valid = your_validate_key( $_REQUEST['mc_api_key'] );
	}

	return $valid;
}
add_filter( 'mc_api_key', 'your_api_key' );

Settings – General

General Settings is located under My Calendar > Settings > General.

My Calendar > Settings > General

My Calendar Management

Calendar Page Location

“My Calendar” is the title automatically added to the page that is created to display the calendar. You can edit this page as a normal page at Pages > All Pages.

Default sort order for Admin Events List

The Events screen columns can be ordered by Event ID, Title, Date/Time, Author, Category and Location. One can also directly reorder the Event list by clicking the column headings on the Events screen.

Default sort direction

Descending (Z-A) or Ascending (A-Z).

Checkbox clicked: for Pretty Permalinks will show a similar slug to this example. https://example.com/mc-events/a-new-event/?mc_id=1

Website name / events base / event title / event ID.

Checkbox not clicked: not showing pretty permalinks will show a similar slug to this example. https://example.com/my-calendar/?mc_id=1

It will not use the events base in the slug.

With pretty permalinks enabled, single event views are rendered using your theme’s single.php template file. Otherwise, single event views are rendered by the My Calendar shortcode on your calendar page.

Go to Settings > Permalinks to change the base URL for events and locations.

My Calendar WordPress plugin. Setting Permalinks for Events and Locations.


The following example in changing mc-events to concerts with pretty permalinks activated: https://example.com/concerts/a-new-event/?mc_id=4

Advanced section

Get data (events, categories and locations) from a remote database.

This option allows you to share data between multiple sites if they all need matching calendars.

  1. It requires you to enable remote database access on the source site as a hosting option in the hosting control panel or by contacting your host.
  2. Once you enable the option, you will need to add code to your theme’s functions.php file to make the remote connection work.
function mc_remote_db() {
        $mcdb = new wpdb('DB_USER','DB_PASSWORD','DB_NAME','DB_ADDRESS');
        return $mcdb;
}

Replace the above placeholders with the host-site database information. The two sites must have the same WordPress table prefix. While this option is enabled, you may not enter or edit events through this installation.

Enabling a remote data connection will disable Adding and Managing Events, Locations, and Categories, as all that data will be drawn from the remote database. Scripts, settings, and styles are still managed from the local installation.

Example:
You own two movie theaters, and they show the same movies at the same times. Rather than enter every event twice, you can remotely access the database for theater 1 so that both theaters display exactly the same event information. The two sites can have completely different designs, and show calendars in different ways, but share the same events.

Enable external API

Enable to acquire custom event data in JSON, CSV, or iCal (.ics). When you enable the External API, the URL for requests to your API will be displayed. This API does not use the WordPress REST API.

A REST API is available for My Calendar if you have My Calendar Pro activated. Read more about the Enable external API.

Drop MySQL tables on uninstall

Check this option prior to uninstalling My Calendar to also delete all event data.

Delete plugin settings on uninstall

Check this option prior to uninstalling if you wish to delete all the settings you have configured.

Settings on other screens

Settings > Permalinks: Events permalink slug (mc-events)
Settings > Permalinks: Location permalink slug (mc-locations)
Settings > General: First day of the week

My Calendar: Setting Permalinks for Events and Locations.

General WordPress settings

There are two important settings controlled outside the plugin:
the time zone events are displayed in and the day of the week the calendar starts on. These options are set from the WordPress general settings: Dashboard > Settings > General.

Next: My Calendar > Settings > Text.