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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.