<?php

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

$args = array(
	'post_type' => 'trivia',
	'orderby' => 'rand',
	'posts_per_page' => '3',
);
$query = new WP_Query( $args );
?>
<div id="<?php echo $id; ?>" class="bw-gcbc-trivia">
	<?php if ( $query->have_posts() ) : ?>
		<div class="bw-trivia-cards">
			<?php while ( $query->have_posts() ) : $query->the_post(); ?>
				<div class="flip-card">
					<div class="flip-card-inner bw-skip-fade">
						<div class="flip-card-back">
							<div class="bw-back-wrap">
								<div>
									<div>
										<h3><?php the_title(); ?></h3>
										<div><?php the_field('back', get_the_ID()); ?></div>
									</div>
									<div>
										<?php if (get_field('button', get_the_ID())) : ?>
											<a class="button" href="<?php the_field('button_link', get_the_ID()); ?>">
												<?php the_field('button_label', get_the_ID()); ?>
											</a>
										<?php endif; ?>
									</div>
								</div>
							</div>
						</div>
						<div class="flip-card-front">
							<div class="thumbnail">
								<?php the_post_thumbnail('large'); ?>
							</div>
							<div>
								<h3><?php the_title(); ?></h3>
								<div><?php the_field('front', get_the_ID()); ?></div>
							</div>
						</div>
					</div>
				</div>
			<?php endwhile; ?>
		</div>
	<?php endif; ?>
	<?php wp_reset_postdata(); ?>
</div>