WordPress redundant posts help needed

Hi guys,

I have a loop that I use to render films that will be showing using a custom meta field. The custom date field has a repeater and can appear multiple times, e.g.

1: Exciting movie

  • Show Date: 14/01/2017 09:00
  • Show Date: 15/04/2018 17:00
  • Show Date: 23/06/2018 09:00

2: But I do not want to display a date that has passed, e.g. first date

  • Show Date: 14/01/2017 09:00 [useless date now based on today’s date]

3: This is my script but it shows repeating movies. I want it that if a movie is on the schedule (has a future date, only display it one). The rest of the dates can be viewed on the single page.

    <div class="bet-slider">

    <h2>Coming Soon</h2>

    <?php
        $args = array(
            'post_type'         => 'films',
            'posts_per_page'    => -1,
            /** limited to twenty shows, the rest can be viewed in the tv schedule **/
            'order'				=> 'ASC',
            'orderby'			=> 'meta_value',
            'meta_key'			=> 'airing_date_and_time',
            'meta_type'			=> 'DATETIME'
        );

        $loop = new WP_Query( $args );
    ?>

    <?php if ( $loop->have_posts() ) : ?>

        <ul id="bet-slides" class="bxslider">
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                <?php

                    // get show times
                    $show_times = get_field('airing_date_and_time', get_the_ID() );

                    $post_id = get_the_id();


                    foreach($show_times as $show_time_array) {

                        // return valid times :-)
                        $show_time = $show_time_array['show_date_and_time'];
                        $ObjectShowTime = \DateTime::createFromFormat("Y-m-d H:i", $show_time);
                        $show_time_clean = $ObjectShowTime->format("Y-m-d H:i");

                        // get the date today
                        $cur_date = current_time('Y-m-d H:i', 2 );


                        // display shows in the future only
                        if($cur_date < $show_time_clean) { ?>

                            <li>
                                <a href="<?php the_permalink(); ?>">
                                    <img src="<?php echo get_field('film_cover');?>" alt="<?php echo get_the_title();?>" />
                                </a>
                                <?php //echo "Show date :" . $ObjectShowTime->format("Y-m-d H:i"); ?>
                            </li>

                        <?php }  ?>

                    <?php }

                ?>

            <?php endwhile; ?>
        </ul>

    <?php endif; ?>

    <?php wp_reset_postdata(); ?>

</div>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.