• Resolved kiccokeys

    (@kiccokeys)


    Hello,
    as I try to loop the upcoming events like this:

    
    <?php
      $loop = new WP_Query( array(
        post_type' => 'mep_events',
        'posts_per_page' => 3
        )
       );
    ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <h2><?php the_title(); ?></h2>
        <span><?php do_action('mep_event_date'); ?></span>
    <?php endwhile; wp_reset_query(); ?>

    what i get is that, instead of event date, I get CURRENT date.
    Is there something i’m doing wrong?

    Thanks a lot, regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kiccokeys

    (@kiccokeys)

    I solved like this (if can be helpful)

    //inside the loop
    $date = get_post_meta($post->ID, 'event_start_date', true); if($date != ''){echo date("j F Y", strtotime($date));
    $time = get_post_meta($post->ID, 'event_start_time', true); if($time != ''){echo date("H:i", strtotime($time));} 
    //inside the loop
    Plugin Contributor Md. Abdullah Al Mahim

    (@aamahin)

    Instead of using date function, you can use get_mep_datetime($date,$type) this function to display the correct date because date returns the server DateTime.

    It will display the date according to wp date settings
    echo get_mep_datetime($date,’date’);

    It will display the date as text according to wp date settings
    echo get_mep_datetime($date,’date-text’);

    It will display the date & time according to wp date settings
    echo get_mep_datetime($date,’date-time’);

    It will display the date text as text according to wp date settings
    echo get_mep_datetime($date,’date-time-text’);

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wrong date in post loop’ is closed to new replies.