<?php get_header();?>
<?php 
   $termID = get_queried_object()->term_id;
   //$term = get_term( $termID );
?>
<section class="listing-sec">
 <div class="container"> 
  <div class="row">
       <div class="col-lg-12"> 
               <div class="innere-heading-sec termimage">
                     <h2><?php single_term_title();?></h2>
                     <?php echo term_description( $termID,'book-tag' ); ?>
                </div> 
</div>
       </div>
       <form method="get" id="advanced-searchform" role="search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
       <input type="hidden" name="search" value="advanced">
       <div class="row search-bar">
         <div class="col-lg-3">
         <input type="text" class="form-control" name="title" id="title" placeholder="Title">
         </div>
          <div class="col-lg-3">
            <select name="author" id="author" class="form-control">
               <option selected="selected" value="">Author</option>
               <?php
                $blogusers = get_users( array( 'role__in' => array( 'author' ) ) );
                foreach ( $blogusers as $user ) { ?>
                   <option value="<?php echo $user->ID; ?>"><?php echo $user->display_name;  ?></option>
                <?php } ?>
            </select>
         </div>
         <div class="col-lg-3">
         <input type="number" name="year" id="year" class="form-control" min="0" max="9999" placeholder="Year">
         </div>
         <div class="col-lg-3">
         <input type="submit" class="src-btn" value="Search"> 
         </div>
       </div> 
       </form>   
	  <div class="row">
	  	<?php
       $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
			
				 $args = array(
						   'posts_per_page' => 6,
						   'post_type' => 'book',
                           'paged' => $paged,
						   'order'  => 'DESC',
					       'tax_query' => array(
							array(
							'taxonomy' => 'book-tag', 
							'field' => 'term_id',
							'terms' => $termID
							 )
						  )
						);						
				$loop = new WP_Query( $args );						
				if($loop->have_posts()) : while($loop->have_posts()) : $loop->the_post();
		     ?>
		
	  	<div class="col-lg-2 col-6 flip-gap-sec">
                     <div class="flip-card">
                        <div class="flip-card-inner">
                           <div class="flip-card-front">
                              <?php the_post_thumbnail('full',array('class' => 'img-fluid')); ?>
                              <div class="audio-book-title-sec">
                                 <h4><?php echo get_the_title();?></h4>
                              </div>
                           </div>
                           <div class="flip-card-back">
                              <div class="audio-book-hover-sec" >
                                 <div class="short-desc">
                                    <h5><?php the_title();?></h5>
                                    <div class="short-author"><i class="fa fa-user" aria-hidden="true"></i> <?php the_author(); ?></div>
                                    <ul>
                                       <li><i class="fa fa-star" aria-hidden="true"></i></li>
                                       <li><i class="fa fa-star" aria-hidden="true"></i></li>
                                       <li><i class="fa fa-star" aria-hidden="true"></i></li>
                                       <li><i class="fa fa-star" aria-hidden="true"></i></li>
                                       <li><i class="fa fa-star" aria-hidden="true"></i></li>
                                    </ul>
                                    <div class="description">
                                    <p><?php echo wp_trim_words( get_the_content(), 6, '...' ); ?></p>
                                       <a href="<?php the_permalink();?>" class="short-desc-btn">Read More</a>
                                    </div>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
                 <?php endwhile; ?>
<?php if (function_exists("pagination")) { pagination($loop->max_num_pages); } ?>
<?php endif; ?>
	  </div>
	</div>
</section>
<?php get_footer();?>