0

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( 
    array(
        'post_type' => 'event',
        'posts_per_page' => 999,
        'post_status' => 'publish',
        'meta_key'=>'event_date',  
        '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') ) {
        $count++;
        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>';
        }
    }
endwhile;

wp_reset_postdata();
echo '</ul>';

1 Answer 1

0

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 );
2
  • 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 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
    Aug 19, 2014 at 19:50

Your Answer

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

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