/home/bdqbpbxa/demo-subdomains/lafinteca.goodface.com.ua/wp-content/themes/lafinteca/events.php
<?php
// Template name: Events

get_header();

$curr_lang = pll_current_language();
$template_directory = get_template_directory_uri();
$srcset = "srcset='{$template_directory}/assets/images/lazyload.png'";
?>

<main>

    <?php
    get_template_part('templates/blocks/breadcrumbs');
    ?>

    <?php
    $main = get_field('main');
    ?>
    <section class="events-hero" data-animate-group="list">
        <div class="container">
            <div class="title title-1 mob-title-1" data-animate="word">
                <?php echo $main['title']; ?>
            </div>
        </div>
    </section>

    <?php
    $methods = get_field('methods');
    ?>
    <section class="events-current">
        <div class="container">
            <div class="events-current-wrapper">
                <?php
                $current_date = date('Y-m-d H:i:s');
                $args = array(
                    'post_type' => 'event',
                    'posts_per_page' => -1,
                    'meta_query' => array(
                        'relation' => 'AND',
                        array(
                            'key' => 'end_date',
                            'value' => $current_date,
                            'compare' => '>=',
                            'type' => 'DATETIME',
                        ),
                    ),
                    'meta_key' => 'end_date',
                    'orderby' => 'meta_value',
                    'order' => 'ASC',
                );
                $query = new WP_Query($args);

                if ($query->have_posts()) :
                    foreach ($query->posts as $card) :
                        $start_date = get_field('start_date', $card->ID);
                        $end_date = get_field('end_date', $card->ID);
                        $place = get_field('place', $card->ID);
                        $mainImg = get_field('image', $card->ID);
                        ?>
                        <div data-animate="swim-top" class="events-current-item" data-offset="0.1">
                            <div class="events-current-item-body">
                                <div class="events-current-item-body-wrapper">
                                    <h3 class="title title-3 mob-title-3 --supply"><?php echo $card->post_title; ?></h3>
                                    <div class="events-current-item-info title-6 mob-title-6">
                                        <p class="date">
                                            <?php

                                            $start_date_timestamp = strtotime($start_date);
                                            $end_date_timestamp = strtotime($end_date);

                                            $locale = pll_current_language('locale');
                                            setlocale(LC_TIME, $locale);

                                            $start_day = date('j', $start_date_timestamp);
                                            $start_month = date('M', $start_date_timestamp);

                                            $end_day = date('j', $end_date_timestamp);
                                            $end_month = date('M', $end_date_timestamp);

                                            if ($start_month == $end_month) {
                                                echo $start_day . '-' . $end_day . ' ' . $start_month . ', ' . date('Y', $end_date_timestamp);
                                            } else {
                                                echo $start_day . ' ' . $start_month . ' - ' . $end_day . ' ' . $end_month . ', ' . date('Y', $end_date_timestamp);
                                            }
                                            ?>
                                        </p>

                                        <p class="time"><?php echo $place; ?></p>
                                    </div>
                                    <div class="text text-2 mob-text-2"
                                         data-accordion-group="event-accordion"><?php echo get_the_content(null, null, $card->ID); ?></div>
                                    <div class="more text-2 mob-text-2">
                                        <span>
                                             <?php
                                             $global_events_texts = get_field("global_texts-{$curr_lang}", 'option')['events'];
                                             echo $global_events_texts['read_more'];
                                             ?>
                                        </span>
                                    </div>
                                </div>
                                <button class="default-button"
                                        data-to-modal="contact-form-popup">   <?php echo $main['event_button']; ?></button>
                            </div>
                            <div class="events-current-item-image">
                                <img class="-lazyload" src="<?php echo $mainImg; ?>" <?php echo $srcset; ?>
                                     alt="<?php the_title(); ?>">
                            </div>
                        </div>
                    <?php
                    endforeach;
                else :
                    echo '<p>We haven`t events now</p>';
                endif;
                ?>
            </div>
        </div>
    </section>

    <section class="events-delayed-title" data-animate-group="list">
        <div class="container">
            <div class="title title-1 mob-title-1" data-animate="word">
                <?php echo $main['delayed_title']; ?>
            </div>
        </div>
    </section>

    <section class="events-delayed">
        <div class="container">
            <div class="events-delayed-wrapper">

                <?php
                $paged = isset($_POST['paged']) ? $_POST['paged'] : 1;
                $args = array(
                    'post_type' => 'event',
                    'posts_per_page' => 4,
                    'paged' => $paged,
                    'meta_query' => array(
                        'relation' => 'AND',
                        array(
                            'key' => 'end_date',
                            'value' => $current_date,
                            'compare' => '<',
                            'type' => 'DATETIME',
                        ),
                    ),
                    'meta_key' => 'end_date',
                    'orderby' => 'meta_value',
                    'order' => 'DESC',
                );
                $post_count = $query->post_count;
                $query = new WP_Query($args);
                if ($query->have_posts()) :
                    while ($query->have_posts()) : $query->the_post();
                        $start_date = get_field('start_date');
                        $end_date = get_field('end_date');
                        $place = get_field('place');
                        $mainImg = get_field('image');
                        ?>
                        <div data-animate="swim-top" class="events-delayed-item" data-offset="0.1">

                            <div class="events-delayed-item-image">
                                <img class="-lazyload" <?php echo $srcset; ?> src="<?php echo $mainImg; ?>"
                                     alt="<?php the_title(); ?>">
                            </div>
                            <div class="events-delayed-item-body">
                                <h3 class="title title-4 mob-title-4 --supply"><?php the_title(); ?></h3>
                                <div class="events-delayed-item-info">
                                    <p class="date">
                                        <?php

                                        $start_date_timestamp = strtotime($start_date);
                                        $end_date_timestamp = strtotime($end_date);

                                        $locale = pll_current_language('locale');
                                        setlocale(LC_TIME, $locale);

                                        $start_day = date('j', $start_date_timestamp);
                                        $start_month = date('M', $start_date_timestamp);

                                        $end_day = date('j', $end_date_timestamp);
                                        $end_month = date('M', $end_date_timestamp);

                                        if ($start_month == $end_month) {
                                            echo $start_day . '-' . $end_day . ' ' . $start_month . ', ' . date('Y', $end_date_timestamp);
                                        } else {
                                            echo $start_day . ' ' . $start_month . ' - ' . $end_day . ' ' . $end_month . ', ' . date('Y', $end_date_timestamp);
                                        }
                                        ?>
                                    </p>
                                    <p class="time"><?php echo $place; ?></p>
                                </div>
                            </div>
                        </div>
                    <?php
                    endwhile;
                    wp_reset_postdata();
                else :
                    echo '<p>We haven`t events now</p>';
                endif;
                ?>
            </div>
            <?php if ($post_count - 4 > 4) : ?>
                <button id="show-more-button" class="default-button -transparent -arrow-bottom show-more-button"
                        data-post-count="<?php echo $post_count; ?>">
                    <span>show more</span>
                </button>
            <?php endif; ?>
        </div>
    </section>

    <div class="modals">
        <?php echo get_template_part('templates/blocks/popup-form'); ?>
    </div>
</main>

<?php
get_footer();
?>