<?php
$args = array('hide_empty' => 1, 'taxonomy' => 'publications-type');
$terms = get_terms($args);
if (!empty($terms) && !is_wp_error($terms) && empty($atts['term'])) {
    $count = count($terms);
    $i = 0;
    ?>
    <div class="" style="display: inline-flex;">
        <p class="" style="margin: auto;">Ou choisir un type</p>
        <form class="" action="" style="margin-left: 20px;">
            <select onchange="location = this.value;" id="rubrique-select" name="rubrique-select" class="form-control">
                <option value="<?php echo get_permalink() ?>" selected>Toutes</option>
                <?php
                foreach ($terms as $term) {
                    $i++;
                    if (single_term_title('', false) == $term->name) {
                        echo '<option value="' . get_term_link($term) . '" selected>' . $term->name . '</option>';
                        } else {
                        echo '<option value="' . get_term_link($term) . '">' . $term->name . '</option>';
                        }
                    }
                ?>
            </select>
        </form>
    </div>
<?php } ?>
<div class="row py-5">
    <?php
    global $wp_query;
    $maPage = get_query_var('paged');
    $args_publications = array(
        'post_type' => 'publications',
        'post_status' => 'publish',
        'posts_per_page' => 9,
        'paged' => $maPage
    );

    if (isset($atts['cat']) && isset($atts['term']) && !empty($atts['term'])) {
        $args_publications['tax_query'] = array(
            array(
                'taxonomy' => $atts['cat'],
                'field' => 'id',
                'terms' => explode(',', $atts['term'])
            )
        );
        }
    $wp_query = new WP_Query($args_publications);
    if ($wp_query->have_posts()) {
        while ($wp_query->have_posts()) {
            $wp_query->the_post();
            ?>
            <div class="mag-card col-12 mt-2">
                <h3 class="mag-card__date_ssImage">
                    <?php echo get_the_title(); ?>
                </h3>
                <a href="<?php echo get_the_permalink() ?>" class="btn btn-secondary"> <span> Consulter </span>
                    <svg xmlns="http://www.w3.org/2000/svg" width="14" height="22">
                        <use href="<?php echo get_template_directory_uri() ?>/dist/sprite.svg#icon-caret-right" />
                    </svg>
                </a>
                <hr class="hr__sm">
            </div>
            <?php
            wp_reset_postdata();
            }
        } else {
        echo '<p>Il n\'y a aucune publication pour l\'instant</p>';
        }
    ?>
</div>
<?php get_template_part('template-parts/content/content-prev-next', array('prevText' => 'Publications plus récentes', 'nextText' => 'Publications plus anciennes')); ?>