Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter OLTEA.cz

    (@olteacz)

    Hi once more. Now I have both dates as post meta, this is solved, but dates are in this format: 2014-03-01T00:00 to 2014-04-21T00:00.
    How can I have dates as “human date” in single post meta value? Like 1.3.2014 to 21.4.2014.
    Thank you!

    Hi Oltea,

    Since the dates are stored in a standardized format, you can easily transform them with the PHP date() function (or the date_i18n() WP function if you need it localized).

    For example, to transform the start date into 1.3.2014, your code would be:

    $event_date_start = get_post_meta($post->ID, 'name_of_field', true);
    
    if (!empty($event_date_start)) {
        echo '<p>Start date: '. date( "j.n.Y", $event_date_start).'</p>';
    }
    Thread Starter OLTEA.cz

    (@olteacz)

    Thank you, Manuel,
    this helped me. But date is always 1.1.1970, not the event date. Any idea?
    Thank you…

    It probably means that you don’t get the content of the custom fields, and PHP returns a dummy result.

    Best is to display the raw custom field – echo get_post_meta(….). This should help you to debug.

    Plugin Author Bastien Ho

    (@bastho)

    Hi

    the plugin comes with a function to display human dates :

    global $EventPost,$post; //assuming that you have a $post defined
    
    $event = $EventPost($post);
    $time=strtotime($event->start);
    $humandate=$EventPost->human_date($time,'j.n.Y');

    the function checks for special days as “today”, “yesterday” and “tomorrow”.

    for other dates, its uses the native date_i18n() WP function

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get meta in sigle post’ is closed to new replies.