I tried this code which I made but looks like I am not doing it correctly..

The main problem is my code fetches all posts ordered by meta value date, but I need to hide the posts from the date today (which I am unable to do), so I did this from php strtotime (which is also fine), but the main issue is I need only 5 latest posts...

If some one can give a tip to get this code to work it would be great

echo '<ul class="whats-on" id="owl-demo">';
global $wp_query;
$tDate = strtotime('now');
$query = new WP_Query( 
        'post_type' => 'event',
        'posts_per_page' => 999,
        'post_status' => 'publish',
        'orderby' => 'meta_value', 
        'order' => ASC
$count = 0;

while ( $query->have_posts() ) : $query->the_post();
    $database_date = get_field('event_date');
    if( strtotime($database_date) > strtotime('now') ) {
        if ($count !="6") {
            echo '<li class="item">';
            echo '<a href="' . the_permalink() . '">';
            echo '<img src="' . bloginfo('template_url') . '/timthumb.php?src=' . the_field('cover') . '&w=170&h=228" class="img-responsive">';
            echo '<h2>' . get_the_title() . '</h2><p>';
            $originalDate = get_field('event_date');
            $newDate = date("l M d", strtotime($originalDate));
            echo $newDate . '</p></a></li>';

echo '</ul>';

1 Answer 1


Do the other post have to be set to draft? Or would just showing today's post work? If just showing today's post works you could do something like the following

$today = getdate();
$args = array(
    'category_name' => 'event',
    'posts_per_page' => 5,
    'year' => $today["year"],
    'monthnum' => $today["mon"],
    'day' => $today["mday"]
query_posts( $args );
  • Sorry for the confusion, i want to make all posts as draft before Today.. its an Events custom post type so basically just want to hide all posts from custom post.. as pasts events Commented Aug 18, 2014 at 15:50
  • You might then need to create a CRON job that runs every night at midnight which runs a sql command to set any post from the previous day to draft.
    – Cvongrim
    Commented Aug 19, 2014 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.