Skip to content

Date

A date picker field for selecting and storing dates.

Date Field

The Date field provides a date picker for selecting a specific date. Use it for event dates, expiry dates, publication dates, or any field requiring date input.


Field Settings

SettingDescription
Field KeyUnique identifier. Lowercase letters and underscores only.
LabelDisplay label shown above the field.
DescriptionOptional helper text shown below the field.
Default ValueOptional default date.

Return Value

Returns a string in Y-m-d format (e.g. "2025-12-25"). Returns an empty string if no value is saved.


Usage

php

// Get the value
$date = onemeta_get_meta( get_the_ID(), 'field_key' );

if ( ! empty( $date ) ) {
    // Convert to timestamp
    $timestamp = strtotime( $date );

    // Format using WordPress locale-aware function
    echo date_i18n( get_option( 'date_format' ), $timestamp );

    // Or format manually
    echo date( 'F j, Y', $timestamp ); // December 25, 2025
}

Template Example

php

<?php $event_date = onemeta_get_meta( get_the_ID(), 'event_date' ); ?>

<?php if ( ! empty( $event_date ) ) : ?>
    <time class="event-date" datetime="<?php echo esc_attr( $event_date ); ?>">
        <?php echo esc_html( date_i18n( 'F j, Y', strtotime( $event_date ) ) ); ?>
    </time>
<?php endif; ?>

Notes

  • The raw value is always stored and returned in Y-m-d format regardless of your WordPress date format setting
  • Use date_i18n() instead of date() to respect WordPress locale and timezone settings
  • Use esc_attr() on the raw date for HTML attributes like datetime

On This Page