Support Log in

13. Date, Time, and Color Fields

Developer Guide
Prefer video? Watch the Field Forge tutorials 8 short guides covering every feature Watch

Fields for temporal data and visual styling values.

Date Picker

Returns the stored date string. The date box of the post editor stores Y-m-d. If the field has a return_format, get_field() formats the stored date with it; the field group editor has no input for return_format, and a field imported from ACF carries one.

php
$date = get_field( 'event_date' );
// Stored internally as 'Y-m-d' (e.g., '2024-12-25').
// `return_format` controls what get_field() returns: when unset, you get the
// raw stored value (`Y-m-d`); when set to a PHP date format like `F j, Y`,
// the field re-formats automatically.

echo '<time datetime="' . esc_attr( $date ) . '">' . esc_html( $date ) . '</time>';

// Parse and reformat ad hoc
$raw = get_field( 'event_date' );
$timestamp = strtotime( $raw );
echo '<p>Event: ' . date_i18n( 'l, F j, Y', $timestamp ) . '</p>';

// Compare dates
$event_date = get_field( 'event_date' );
$now = current_time( 'Y-m-d' );
if ( $event_date && strtotime( $event_date ) >= strtotime( $now ) ) {
    echo '<span class="upcoming">Upcoming</span>';
} else {
    echo '<span class="past">Past Event</span>';
}

Time Picker (Free)

Returns a time string.

php
$time = get_field( 'opening_time' );
// Returns the stored time string. If the field has a return_format (the field group editor
// has no input for it; a field imported from ACF carries one), the time is formatted with it.

echo '<span class="time">' . esc_html( $time ) . '</span>';

// Combine date and time
$date = get_field( 'event_date' );
$time = get_field( 'event_time' );
echo '<p>Event: ' . esc_html( $date ) . ' at ' . esc_html( $time ) . '</p>';

Color Picker

Returns the stored color string. The color box of the post editor stores a hex color such as #ff5733. The field group editor has no opacity setting (the Enable Opacity default is not read by any code), and a value imported from ACF is copied as ACF stored it.

php
$color = get_field( 'brand_color' );
// Returns the stored color string, e.g. '#ff5733'

echo '<div style="background-color: ' . esc_attr( $color ) . ';">Colored block</div>';

// Use as CSS custom property
$primary = get_field( 'primary_color', 'options' );
$secondary = get_field( 'secondary_color', 'options' );
echo '<style>:root { --color-primary: ' . esc_attr( $primary ) . '; --color-secondary: ' . esc_attr( $secondary ) . '; }</style>';

—

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs