<?php 
    /* Template Name: Offers page */ 
    get_header(); 
    global $wp_query; 
?>

	<div class="content inner archive archiveOffer">
		<header class="breadcrump breadOffer">
			<div class="container">
                <div class="links"><a href='<?php echo esc_url( home_url( '/' ) ); ?>'>Home</a><span> / </span><h1>Offers</h1></div>
                <button class="bt-filter mobileFilter">Filter</button>
                <nav class="breadcrumb__filter js-offer-filters js-filters">
                    <div class="filterHeader mobileFilter">
                        <button class="bt-closeFilter">Close</button>
                        <span>Filter</span>
                        <a href="#" class="btReset">Reset all</a>
                    </div>
                    <div class="selects">
                        <select class="js-filter-select breadcrumb__filter__select selectCategory" data-type="cat">
                            <option value="">Category</option>
                            <?php
                                $terms = get_terms(array('taxonomy' => 'category_offer', 'hide_empty' => 1));
                                foreach ($terms as $term) echo '<option value="'. $term->slug .'">'. $term->name .'</option>';
                            ?>
                        </select>

                        <select class="js-filter-select breadcrumb__filter__select selectOrderby" data-type="orderby">
                            <option value="">Sort by</option>
                            <option value="date" data-order="DESC">Date DESC</option>
                            <option value="date" data-order="ASC">Date ASC</option>
                            <option value="name" data-order="ASC">Name A...z</option>
                            <option value="name" data-order="DESC">Name Z...a</option>
                        </select>

                        <button class="btFilterOk mobileFilter">Filter</button>
                    </div>
                </nav>
            </div>
            
        </header>
        <div class="contentPageOffers container">
            <div id="listOffers" class="listOffers posts-list">
                <?php
                    $args = array(
                        'post_type' => 'offer', 
                        'posts_per_page' => 4, 
                        'orderby' => 'date', 
                        'order' => 'DESC', 
                        // 'meta_key' => 'ending_date', 
                        // 'meta_value' => date('Y-m-d'), 
                        // 'meta_compare' => '>='
                    );
                    query_posts($args);
                ?>
                <div class="contentResult">    
                    <?php if (have_posts()) : ?>
                        <?php while (have_posts()) : the_post(); ?>
                            <?php loop_offer($post->ID, 'yes'); ?>
                        <?php endwhile; ?>
                    <?php endif; ?>
                </div>
            </div>
            
            <?php // load more ajax
                $wp_query->query_vars['search_orderby_title'] = ''; // necessario pro search
                $load_posts = $wp_query->query_vars; $load_current_page = $wp_query->query_vars['paged']; $load_max_page = $wp_query->max_num_pages;
                loadmore_button($load_posts, $load_current_page, $load_max_page);
                if($wp_query->max_num_pages > 1){ ?>
                    <span class="js-loadmore  bt-offer bt-category">Load more</span>
                <?php } else { ?>
                    <span class="js-loadmore  hidden">Load more</span>
                <?php } // end load more ajax

                wp_reset_query(); wp_reset_postdata(); 
            ?>
        </div>
	</div><!-- .content.inner.blog -->

		
<?php get_footer(); ?>