<?php
$id = "$block[id]";
if(!empty($block['anchor'])) {
	$id = $block['anchor'];
}

$post_type = get_field('post_type');
if (empty($post_type)) $post_type = 'post';

$filter_term = get_field('filter_term');
if (is_int($filter_term)) $filter_term = get_term($filter_term);

$limit = get_field('post_limit');
if (empty($limit)) $limit = 5;

$args = array(
	'post_type' => $post_type,
	'posts_per_page' => $limit
);
if ($filter_term) {
	$args['tax_query'] = array(array(
		'taxonomy' => $filter_term->taxonomy,
		'terms' => $filter_term->term_id
	));
}

$the_query = new WP_Query($args);
$active = true;
?>
<div id="<?php echo $id; ?>" class="bw-slider">
	<?php if ($the_query->have_posts()) : ?>
		<div id="<?php echo $id; ?>" class="bw-slides">
				<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
					<div class="bw-slide<?php if ($active) { echo ' active'; $active = false; } ?>">
						<div class="bw-slider-content">
							<?php the_content(); ?>
						</div>
						<div>
							<?php the_field('name', get_the_ID()); ?> <?php the_field('title', get_the_ID()); ?><br>
							<?php the_field('company_name', get_the_ID()); ?>
						</div>
					</div>
				<?php endwhile; ?>
			<!-- <div class="bw-buttons">
				<a class="bw-prev"></a>
				<a class="bw-next"></a>
			</div> -->
		</div>
		<div class="bw-dots">
			<?php for ($i = 0; $i < $the_query->found_posts; $i++) : ?>
				<span class="bw-dot" data-slide="<?php echo $i; ?>"></span>
			<?php endfor; ?>
		</div>
	<?php endif; wp_reset_postdata(); ?>
</div>
<?php
