Support

Account

Home Forums General Issues Load posts with specific date from date and time picker

Helping

Load posts with specific date from date and time picker

  • Hi

    I’m new to this plugn, and I’m trying to wrap my head around the functionality. I’m getting close to what I want to do, but I can’t pull it off.

    I’m creating a calendar for a movie festival. I have one post for each movie. Each movie will be shown two times, over a period of three days.

    Each movie has two custom fields (screening1 and screening2) with a date and time picker, where I pick the screening times for the film.

    What I want to do is create a list of films shown on a given day: 16th of november 2017, 17th of november 2017, 18th of november 2017, and then sort the films by starting time.

    This is my code (I started out trying with just the one screening time).

    <?php
    // query
    $the_query = new WP_Query(array(
    	'posts_per_page'	=> -1,
    	'post_type'		=> 'post',
    	'meta_query' 		=> array(
    		'relation' 		=> 'AND',
    		array(
    	        'key'			=> 'screening1',
    	        'compare'		=> '>=',
    	        'value'		=> '15/11/2017 23:59',
    	    ),
    	    array(
    	        'key'			=> 'screening1',
    	        'compare'		=> '<=',
    	        'value'		=> '17/11/2017 00:01',
    	    )
        ),
    	'order'			=> 'ASC',
    	'orderby'			=> 'meta_value',
    	'meta_key'		=> 'visning1',
    	'meta_type'		=> 'DATE'
    ));
    
    ?>
    <?php if( $the_query->have_posts() ): ?>
    	<ul>
    	<?php while( $the_query->have_posts() ) : $the_query->the_post(); 
    		?>
    		<li>	<div class="mow-cal-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    <div class="mow-cal-featured"><?php the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) ?></div>
    <div class="mow-cal-tema"><?php the_field('tema'); ?></div>
    <div class="mow-cal-spesial"><?php the_field('spesialvisning'); ?></div>
    <div class="mow-cal-visning1"><?php the_field('visning1'); ?></div>
    <div class="mow-cal-visning1-arena"><?php the_field('visning1-arena'); ?></div>
    <div class="mow-cal-button"><a href="<?php the_permalink(); ?>">Les filmomtale</a></div>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?php endif; ?>
    
    <?php wp_reset_query();	 // Restore global post data stomped by the_post().
    ?>

    I hope someone is able help.

    And, if there is a way to let the user select which day is visible, that would be the most amazing thing ever.

  • Have you tried a different format for dates ? I seem to remember something about a certain format…. (not sure, can’t find the link…)

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

The topic ‘Load posts with specific date from date and time picker’ is closed to new replies.