Support

Account

Home Forums Front-end Issues Posts not showing after switching from DatePicker to DateTime Picker

Solved

Posts not showing after switching from DatePicker to DateTime Picker

  • Hello, I’m having a problem here and hope someone can shine a light on its cause. I successfully implemented a datepicker which shows events that fall within a time period. Each period runs from October to March, so it covers two years. A period is a category, to make it easy for the enduser, and determined by startdate and enddate. Posts can be assigned to this category and all was working fine.
    Last week, my client asked to show time as well instead of date only for each event. So I switched to DateTime picker and added the format for time.

    Unfortunately for the current category, all events from this year are not showing anymore (only events from next year are visible). See the screenshots for the difference. I’m clueless why this happens.

    Here’s my (sorry… pretty long) code:

    <?php // This part sets the category for the current period 
        $categories = get_the_category();
       if ( ! empty( $categories ) ) { ?>
    	<h1>Season <?php echo esc_html( $categories[0]->name ); ?></h1>
    	<?php $programma = get_field('programma'); if($programma) { ?>
    	<a href="<?php echo $programma['url']; ?>"><?php echo $programma['filename']; ?></a><?php } ?>
    		
    	<?php // Get the current category, in case it's selected
    	$terms = get_the_terms( get_the_ID(), 'category');
    			
    	// Show start- and enddate for this season
    	if( !empty($terms) ) {
    	$term = array_pop($terms);
    
    	$start_periode 		= get_field('periode_start', $term,'' );								
    	$eind_periode 		= get_field('periode_einde', $term, '');
    	$dateformatstring 	= "d F Y";
    	$unixtimestamp 		= strtotime($start_periode);
    	$start 			= date_i18n($dateformatstring, $unixtimestamp);?>
    				
    	<p>This season starts on <?php echo $start; ?> and ends on <?php echo date_i18n($dateformatstring, strtotime($eind_periode)); ?></p>
    			
    	<?php } ?>
    <?php } ?>
    					
    <?php // show year only once
    	  $y = ''; 
          // compare set eventdate with current date
    	  $dateformatstring = "d F";
    	  $unixtimestamp = strtotime(get_field('datum'));
    		
    	if(!empty($_POST['date'])){
    		$this_date = $_POST['date'];	
    	} $this_year = date_i18n("Ymd", $unixtimestamp);			
    		
    	$event1 = current_time('Ymd');
    	$args = array(
    	'post_type' => 'post',
            'post_status' => 'publish',
    	'posts_per_page' => '-1',
    	'meta_query' => array(
    	   array(
    	   'key' => 'datum',
    	   'compare' => '>=',
    	   'value' => $event1,
    		)
    	   ),
              'meta_key' => 'datum',
    	  'orderby' => 'meta_value',
    	  'order' => 'ASC',
    	  'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    	);
    	
    	$events = new WP_QUERY($args);
    
            // Order all posts within period, upcoming first
    	if ($events->have_posts()) : ?>
    	<ul class="overzicht__huidig">
    		
    	<?php while ( $events->have_posts() ) : $events->the_post(); ?>
    	<li class="overzicht-item"><a href="<?php the_permalink() ?>">
    	<div class="huidige-thumb">
    	   <?php if(has_post_thumbnail()){the_post_thumbnail();}?>
    	</div>
    	    <div class="huidige-meta">
    		<div class="huidige-titel"><h3><?php the_title(); ?></h3></div>
    		 <div class="overzicht-datum">
    			<?php // Get date and time for this event
    			$date = get_field('datum', false, false);
    			$dateformatstring = "l d F Y H:i";
    			$unixtimestamp = strtotime($date); ?>
    														
    		<h4><?php echo date_i18n($dateformatstring, $unixtimestamp); ?></h4>									
    	    </div>
    	</div>	
        </a>
    </li>
    <?php endwhile;?>	
    </ul>
    <?php endif; ?>

    Is $event1 obsolete because of it’s only date? Thank you in advance, for any help!

  • Sometimes, the solution is lying right in front of you and is it better to replace instead of repair. I replace the query with the one from Query posts (now) and all is working as it should.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Posts not showing after switching from DatePicker to DateTime Picker’ is closed to new replies.