Custom field with date data rendering as linux timestamp... dynamic date filters should work for this?

I’m experimenting with https://theeventprime.com.

They don’t provide a lot of useful custom fields currently, but the event date is one of them.

However, when I use it as a dynamic field—which looks like {cf_em_start_date}—it prints like this on the page:

1713644949

(Which is the linux timestamp for the date and time of the event.)

I tried using, e.g., {cf_em_start_date:Y}, but this had no effect.

Just thinking it would be good if we could force any such custom field data into a formatted date (or at least it would attempt to do so) by using the datetime filters?

I.e., this should work.

Thanks!

1 Like

Hi thanks for sharing this link.

How do I bridge this from a StackOverflow answer to using it as a Bricks dynamic content piece?

Thanks again!

Create this custom function:

<?php

function bl_date_from_timestamp_field( string $field, string $format ): string {
    if ( $format === '' ) {
        $format = get_option( 'date_format' );
    }

    $timestamp = get_post_meta( get_the_ID(), $field, true );

    $datetime = new DateTime();
    $datetime->setTimestamp( $timestamp );

    return $datetime->format( $format );
}

Use it like this:

{echo:bl_date_from_timestamp_field(em_start_date,'')}

You can pass any valid date format string as the 2nd argument. If left empty, it will use the one in WP settings.

2 Likes