Support

Account

Home Forums General Issues Only show posts if the date picker date is still in the future or today

Solved

Only show posts if the date picker date is still in the future or today

  • So, I am basically using ACF to manage my custom post type, “Events”. I have it set up so that the posts are ordered by the date picker, having the events closest to today’s date at the top. I want it so that if the event date passes, the event no longer shows up in the loop.

    Here is my code for the loop:

    <?
                    if ( get_query_var('paged') ) {
                      $paged = get_query_var('paged');
                      } else if ( get_query_var('page') ) {
                              $paged = get_query_var('page');
                      } else {
                              $paged = 1;
                      }
                      query_posts( array( 'post_type' => 'events', 'meta_key' => 'event_date', 'orderby' => 'meta_value_num', 'posts_per_page' => 4, 'order' => 'ASC', 'paged' => $paged ) );
                      while (have_posts()) : the_post();
                    ?>

    Any Tips would be awesome, THANK YOU

  • Got this working like this:

    <?
    				
    				$currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
    				
                    if ( get_query_var('paged') ) {
                      $paged = get_query_var('paged');
                      } else if ( get_query_var('page') ) {
                              $paged = get_query_var('page');
                      } else {
                              $paged = 1;
                      }
                      query_posts( array(
                      	'meta_query'=> array(
    	                    array(
    	                      'key' => 'event_date',
    	                      'compare' => '>',
    	                      'value' => $currentdate,
    	                      'type' => 'DATE',
    	                    )),
    	                 'post_type' => 'events',
    	                 'meta_key' => 'event_date',
    	                 'orderby' => 'meta_value_num',
    	                 'posts_per_page' => 4,
    	                 'order' => 'ASC',
    	                 'paged' => $paged ) );
                      while (have_posts()) : the_post();
                    ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.