wp-settings-builder

7. Fields: Date and Time

This guide covers the advanced date and time fields, all of which are powered by the lightweight and powerful Flatpickr library. These fields provide a beautiful and user-friendly interface for selecting dates, times, and ranges.

The framework automatically handles enqueuing all necessary styles and scripts when you use any of these fields.


Core Concepts

A key principle for these fields is the separation of display format from storage format.

The framework handles the translation between these two formats automatically.


Common extras

The following keys in the $extras array are used to configure the date and time fields:


Date

Example

$page->add_field(
    'start_date',
    'event_section', 
    'date', 
    'Event Start Date', 
    [
        'description' => 'The date the event begins.',
        'default'     => date('Y-m-d'), // Defaults to today
        'display_format' => 'F j, Y', // Displays as "October 26, 2025"
        'flatpickr_options' => [
            'minDate' => 'today', // Disables selection of past dates
        ],
    ]
);

Time

Example

$page->add_field( 
    'opening_time', 
    'hours_section', 
    'time', 
    'Opening Time', 
    [
        'description' => 'Select the store\'s opening time.',
        'default'     => '09:00:00',
        'display_format' => 'h:i K', // Displays as "09:00 AM"
    ]
);

Date & Time

Example

$page->add_field( 
    'sale_starts',
    'event_section',
    'date_time', 
    'Sale Starts On', 
    [
        'description' => 'The exact date and time the sale will become active.',
        'display_format' => 'M j, Y @ h:i A', // Displays as "Nov 27, 2025 @ 09:00 AM"
        'flatpickr_options' => [
            'enableSeconds' => false,
            'minuteIncrement' => 15,
        ],
    ]
);

Date Range

Example

$page->add_field(
    'vacation_period', 
    'booking_section', 
    'date_range', 
    'Vacation Period',
     [
        'description' => 'Select the start and end dates of the booking.',
        // The default value must be a PHP array of strings
        'default' => ['2025-08-01', '2025-08-15'],
        'display_format' => 'M j, Y',
    ]
);

Date & Time Range

Example

$page->add_field(
     'maintenance_window',
    'advanced_section', 
    'date_time_range', 
    'Maintenance Window', 
    [
        'description' => 'The website may be unavailable during this period.',
        'display_format' => 'M j, h:i K',
    ]
);

With these fields, you can capture any date or time-based data you need. The next guide covers relational fields, which allow you to link to other WordPress content like posts, users, and terms.

Next: 8. Fields: Relational (AJAX)