Support

Account

Home Forums General Issues How to customize the “Date” field Reply To: How to customize the “Date” field

  • I tried adding this to query a custom post type and it gives an odd timestamp 01 January 1970:

    <?php
    $date = get_field('fromdate', false, false);
    // convert it to a time
    $time = strtotime($date);
    
    if ( get_query_var('paged') ) $paged = get_query_var('paged');  
    if ( get_query_var('page') ) $paged = get_query_var('page');
    
    $query = new WP_Query( array( 'post_type' => 'events', 'posts_per_page' => 20,  'order' => 'ASC' ) ); 
    
    if ( $query->have_posts() ) :
            
            while ( $query->have_posts() ) : $query->the_post(); ?> 
    
    <div class='events-title'>
    <span class="day"><?php echo date('d', $time); ?></span>
    <span class="month"><?php echo date('F', $time); ?></span>
    <span class="year"><?php echo date('Y', $time); ?></span>
    </div>
    
       <?php endwhile; wp_reset_postdata();
    
    else : ?>
            
            <p>There are no events at the moment</p>
    
    <?php endif;?>

    The dateformat is set up to return Ymd.

    Jon