<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
$enable_related_post = Draly_Dropshipping_Starter_Helper::get_option( 'enable_related_post' );
if ( empty( $enable_related_post ) ) {
	return;
}
global $post;
$tags = wp_get_post_tags( $post->ID );
if ( $tags ) {
	$tag_ids = array();
	foreach ( $tags as $tag ) {
		$tag_ids[] = $tag->term_id;
	}
	$args          = array(
		'tag__in'             => $tag_ids,
		'post__not_in'        => array( $post->ID ),
		'posts_per_page'      => 5,
		'ignore_sticky_posts' => 1
	);
	$related_query = new WP_Query( $args );
	$item_class  = 'post-item rows-space-30 col-12 col-sm-6 col-md-6 col-lg-3 col-xl-3 col-xxl-3';
	if ( $related_query->have_posts() ) {
		?>
        <div class="draly-related-post draly-blog style-01">
            <h3 class="title"><?php echo esc_html__( 'Related Posts', 'draly-dropshipping-starter' ); ?></h3>
            <div class="blog-list-grid row">
				<?php while ( $related_query->have_posts() ) : $related_query->the_post(); ?>
                    <article <?php post_class( $item_class ); ?>>
						<?php get_template_part( '/templates/blog/blog-style/content-blog', 'style-01' ); ?>
                    </article>
				<?php endwhile; ?>
            </div>
        </div>
		<?php
	}
	wp_reset_postdata();
}