<?php 
$paged = get_query_var('paged');
$args = array('post_type' => 'bunch_projects', 'showposts'=>$num, 'orderby'=>$sort, 'order'=>$order, 'paged'=>$paged);
$terms_array = explode(",",$exclude_cats);
if($exclude_cats) $args['tax_query'] = array(array('taxonomy' => 'projects_category','field' => 'id','terms' => $terms_array,'operator' => 'NOT IN',));
$query = new WP_Query($args);

$t = $GLOBALS['_bunch_base'];

$data_filtration = '';
$data_posts = '';
?>

<?php if( $query->have_posts() ):

ob_start();?>

	<?php $count = 0; 
	$fliteration = array();?>
	<?php while( $query->have_posts() ): $query->the_post();
		global  $post;
		$meta = get_post_meta( get_the_id(), '_bunch_projects_meta', true );//printr($meta);
		$meta1 = _WSH()->get_meta();
		$post_terms = get_the_terms( get_the_id(), 'projects_category');// printr($post_terms); exit();
		foreach( (array)$post_terms as $pos_term ) $fliteration[$pos_term->term_id] = $pos_term;
		$temp_category = get_the_term_list(get_the_id(), 'projects_category', '', ', ');
	?>
		<?php $post_terms = wp_get_post_terms( get_the_id(), 'projects_category'); 
		$term_slug = '';
		if( $post_terms ) foreach( $post_terms as $p_term ) $term_slug .= $p_term->slug.' ';?>		
           
		    <!--Gallery Item-->
            <div class="gallery-item masonry-item all <?php echo esc_attr($term_slug); ?> <?php if(manufacto_set($meta1, 'extra_width') == 'extra_width') echo 'col-lg-8 col-md-8 col-sm-12 col-xs-12'; else echo 'col-lg-4 col-md-4 col-sm-6 col-xs-12'?>">
                <div class="inner-box">
                    <figure class="image-box">
                        <?php if(manufacto_set($meta1, 'extra_width') == 'extra_width') 
								$image_size = 'manufacto_770x274'; 
							  elseif(manufacto_set($meta1, 'extra_height') == 'extra_height')
								$image_size = 'manufacto_370x574'; 
							  else
								$image_size = 'manufacto_370x274'; 
							  the_post_thumbnail($image_size);
						?>
                        <!--Overlay Box-->
                        <div class="overlay-box">
                            <div class="overlay-inner">
                                <a href="<?php echo esc_url(get_permalink(get_the_id()));?>" class="image-link"><span class="icon fa fa-link"></span></a>
                                <div class="content">
                                    <h3><a href="<?php echo esc_url(get_permalink(get_the_id()));?>"><?php the_title(); ?></a></h3>
                                    <?php $term_list = wp_get_post_terms(get_the_id(), 'projects_category', array("fields" => "names")); ?>
									<div class="category"><?php echo implode( ', ', (array)$term_list );?></div>
                                </div>
                            </div>
                        </div>
                    </figure>
                </div>
            </div>
            
<?php endwhile;?>
  
<?php wp_reset_postdata();
$data_posts = ob_get_contents();
ob_end_clean();

endif ;
ob_start();?>	 

<?php $terms = get_terms(array('projects_category')); ?>

<!--Project Section-->
<section class="project-page-section">
    <div class="auto-container">
        
        <!--Sortable Masonry-->
        <div class="sortable-masonry">
            
            <!--Filter-->
            <div class="filters clearfix">
                <ul class="filter-tabs filter-btns clearfix">
                    <li class="active filter" data-role="button" data-filter=".all"><?php esc_attr_e('View All', 'manufacto');?></li>
                    <?php foreach( $fliteration as $t ): ?>
                    <li class="filter" data-role="button" data-filter=".<?php echo esc_attr(manufacto_set( $t, 'slug' )); ?>"><?php echo wp_kses_post(manufacto_set( $t, 'name')); ?></li>
                    <?php endforeach;?>
                </ul>
            </div>
            
            <div class="items-container row clearfix">
            	 <?php echo wp_kses_post($data_posts); ?>
            </div>
        </div>
        
        <!--Styled Pagination-->
        <div class="styled-pagination">
            <div class="inner-container clearfix">
                <div class="clearfix text-center">
                    <?php manufacto_the_pagination(array('total'=>$query->max_num_pages, 'next_text' => '<div class="pull-right next-post">Next Post <i class="fa fa-long-arrow-right"></i> </div>', 'prev_text' => '<div class="pull-left prev-post"><i class="fa fa-long-arrow-left"></i> Prev Post </div>')); ?>
				</div>
            </div>
        </div>
    </div>
</section>
<!--End Projects Section-->