<?php
global $post;
$post_type = (!empty($post->post_type)) ? $post->post_type : null;
$collection_ids = wp_get_object_terms($post->ID, 'collection', array('fields' => 'ids'));
$args = array(
    'post_type' => array('movies'),
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'orderby' => 'post_date',
    'post__not_in' => array($post->ID),
    'tax_query' => array(
        array(
            'taxonomy' => 'collection',
            'field' => 'id',
            'terms' => $collection_ids,
        )
    )
);
$col_query = new WP_Query($args);
if ($col_query->have_posts()) : ?>
    <section class="archive-slider rt rt-relative rt-overflow rt-margin">
        <div class="rt">
            <div class="main">
                <div class="title-asli rt">
                    <h3 class="name right rt-18 rt-fff rt-bold">کالکشن این فیلم</h3>
                </div>
                <div class="slider-auto owl-carousel rt rt-relative rt-flex">

                    <?php while ($col_query->have_posts()) : $col_query->the_post();
                        global $post;
                        $post_permalink = get_the_permalink($post->ID);
                        $post_title = get_post_meta($post->ID, 'title_movie', true);
                        $post_title = (!empty($post_title)) ? $post_title : get_the_title($post->ID);
                        $imdb_rate = get_post_meta($post->ID, 'imdb_rate_movie', true);
                        $isDubbed = get_post_meta($post->ID, 'has_dubbed', true);
                        $isSubbed = get_post_meta($post->ID, 'has_subtitle', true);
                        $genre_slug = 'genre';
                        $genres = wp_get_post_terms($post->ID, $genre_slug);
                        $imdb_rate = yc_get_post_meta($post->ID, 'imdb_rate_movie', true);
                        $releases = wp_get_post_terms($post->ID, 'release'); ?>
                        <article class="mini-p rt rt-relative rt-overflow">
                            <figure class="rt rt-relative rt-overflow rt-5px">
                                <?php if (!empty($isDubbed) || !empty($isSubbed)) : ?>
                                    <div class="chasbs">
                                        <?php if (!empty($isDubbed)) : ?>
                                            <span class="dooble rt-fff rt-11 rt-absolute"><i class="fa fa-microphone rt-13 right"></i> دوبله</span>
                                        <?php endif; ?>
                                        <?php if (!empty($isSubbed)) : ?>
                                            <span class="srt dooble rt-fff rt-11 rt-absolute"><i class="fa fa-closed-captioning rt-13 right"></i> زیرنویس</span>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>
                                <a href="<?php echo $post_permalink; ?>"><?php the_post_thumbnail('post_cover', array("class" => "rt")); ?></a>
                                <div class="hover rt rt-absolute rt-center rt-5px">
                                    <a href="<?php echo $post_permalink; ?>" class="full-link rt rt-absolute rt-z-index"></a>
                                    <i class="fa fa-play rt-31 rt-fff"></i>
                                    <?php if (!empty($genres)) :
                                        $count_g = count($genres); ?>
                                        <div class="cat-p rt">
                                            <?php foreach ($genres as $key => $genre) : ?>
                                                <a href="<?php echo get_term_link($genre->term_id, $genre_slug) ?>" rel="category tag"><?php echo $genre->name; ?></a>
                                                <?php if (($key + 1) < $count_g) echo ","; ?>
                                            <?php endforeach; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <?php if (!empty($imdb_rate)) : ?>
                                    <a href="<?php echo $post_permalink; ?>" class="imdb left rt-absolute rt-8px rt-align">
                                        <i class="fa fa-imdb rt-400 rt rt-31"></i>
                                        <span class="rt rt-12 rt-fff"><?php echo $imdb_rate; ?></span>
                                    </a>
                                <?php endif; ?>
                            </figure>
                            <h2 class="title rt rt-14 rt-overflow">
                                <a href="<?php echo $post_permalink; ?>" class="rt-ddd rt"><?php echo $post_title; ?>
                                    <?php if (!empty($releases)) :
                                        $count_r = count($releases); ?>
                                        <?php foreach ($releases as $key => $release) : ?>
                                            <?php echo $release->name; ?>
                                            <?php if (($key + 1) < $count_r) echo "-"; ?>
                                        <?php endforeach; ?>
                                    <?php endif; ?>
                                </a>
                            </h2>
                        </article>
                    <?php endwhile; ?>

                </div>
            </div>
        </div>
    </section>
<?php endif;
wp_reset_query(); ?>