Use Custom Fields as Event Date & Time

This is a developer level document. We only provide limited support for developer-level features.

If you already have a pre-existing Events post type (or similar) with start and end dates entered via a custom field, you may opt to display those via Pie Calendar automatically using the sample code below.

Use Pie Calendar With Advanced Custom Fields

If you're using Advanced Custom Fields (ACF) or a similar plugin, the sample code in this article assumes you are using a "Date Time Picker" field.

The default "Return Format" will work with Pie Calendar.

Things To Consider

Note that this method precludes showing any events on the calendar that use Pie Calendar's built-in date/time picker controls. Only events with the new designated start date meta field will appear on the calendar.

Other Pie Calendar configuration options on these posts should work as intended: all-day status, recurring events (Pro) etc..., but the start date, end date, and "Show on Calendar" toggle will be ignored.

Sample Code

In the example below, replace each instance of "custom_event_start" and "custom_event_end" with your respective meta field names.

Note that end date and time are not required.

Add this code to your themes functions.php or to a code snippet plugin of your choice.

// First, we filter the meta_query in our query that fetches events and tell it to look for posts where
// the meta field 'custom_event_start' isn't blank.
// custom_event_start could be any meta key you want, but it should contain a
// properly formatted date/time (e.g. the default date format for ACF date/time // fields works fine)

add_filter(
"piecal_event_query_args",
function ($args, $atts) {
$args["meta_query"] = [
"relation" => "AND",
        [
            "key" => "custom_event_start",
            "value" => "",
            "compare" => "!=",
        ],
    ];

    return $args;
},
10,
2

);
// Next, we need to tell Pie Calendar to look at our 'custom_event_start' meta key for the start date.
add_filter("piecal_start_date_meta_key", function ($key) {
$key = "custom_event_start";
return $key;

});
// Finally, we tell Pie Calendar to look at our 'custom_event_end' meta key for the end date.
add_filter("piecal_end_date_meta_key", function ($key) {
$key = "custom_event_end";
return $key;

});

Hiding Pie Calendar's Native Fields

These instructions require Pie Calendar Pro.

If you don't need them, Pie Calendar's native fields can be hidden by doing the following:

  1. Create a new post type that is either hidden or will be unused.
  2. Go to Settings > Pie Calendar > Allowed Post Types and tick the box for the new, hidden post type.

Now, all other post types (including the one you're using for events) will no longer have the native Pie Calendar fields. This is useful if you're using custom fields instead of Pie Calendar's native fields and want to reduce clutter and confusion.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.