Hi all,
I’m currently having issues running queries based on the Date Picker field and comparing this with the current date. I’ve opted to set the Return Format to “U” so that it returns a string which I can then compare to a string version of the current date.
What I would like to do is display content on certain pages based on this comparison (greater than current date for “coming soon” and also the opposite for “now showing”). However, it seems that the data is getting very mixed up as I have content that should be on “now showing” which is displaying on “coming soon” instead.
In addition I have the page split so that I can use an ACF to set certain films to be “featured” and therefore not show up in the lower results as well.
Below is the code I have so far and a live deployment can be viewed on the following.
<?php
get_header();
?>
<!-- START - Coming Soon -- Header -->
<section class="comingsoon-header">
<h1 class="section__heading">Coming Soon</h1>
<!-- START - Coming Soon Slider -->
<?php
$dateToday = date("U"); ?>
<p><?php echo $dateToday ?></p>
<?php
$comingSoonFilms = new WP_Query(array(
'post_type' => 'film',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'film_releasedate',
'value' => $dateToday,
'type' => 'DATE',
'compare' => '>',
),
array(
'key' => 'film_active',
'value' => '1',
),
)
));
?>
<?php if ($comingSoonFilms->have_posts()) : ?>
<!-- START - Coming Soon Slider -->
<div class="section__slider-container text-center">
<div class="swiper swiper-container swiper--section swiper--section--filmswide swiper--section--filmswide--comingsoon">
<div class="swiper-wrapper">
<!-- Slides -->
<?php while ($comingSoonFilms->have_posts()) {
$comingSoonFilms->the_post();
if (get_field('film_comingsoon_featured_status') == true) {
?>
<div class="swiper-slide">
<a href="<?php the_permalink(); ?>">
<img src="<?php the_field('film_comingsoon_featured_image'); ?>" alt="" title="" class="swiper__imgbg" />
<div class="comingsoon-header__details">
<p class="comingsoon-header__details__heading"><?php the_title() ?> </p>
<span class="cta">View More</span>
<p class="comingsoon-header__releasedate"><i class="fas fa-clock"></i>Coming: <?php echo date('d/m/Y', get_field('film_releasedate')) ?><br />
<br /><?php echo get_field('film_releasedate') ?></p>
</div>
</a>
</div>
<?php
}
}
?>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</div>
<!-- END - Coming Soon Slider -->
</section>
<!-- START - Coming Soon -- More -->
<section>
<h2 class="section__heading">More Coming Soon</h2>
<div class="filmpanels filmpanels--grid">
<?php while ($comingSoonFilms->have_posts()) {
$comingSoonFilms->the_post();
if (get_field('film_comingsoon_featured_status') == false) {
?>
<div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php echo wp_get_attachment_url(get_field('film_poster')); ?>" alt="" title="" class="swiper__imgbg" />
<p><?php the_title(); ?></p>
<?php echo date('d/m/Y', get_field('film_releasedate')) ?>
<p><?php echo get_field('film_releasedate') ?></p>
</a>
</div>
<?php
}
}
?>
</div>
</section>
<section class="results--pagination">
<?php
echo paginate_links(array(
'total' => $comingSoonFilms->max_num_pages
));
wp_reset_query();
?>
<?php else : ?>
<p>No films currently coming soon!</p>
<?php endif; ?>
</section>
<?php
get_footer();
?>
Thanks in advance