<?php
/**
 * Video related content
 *
 * @package wpstream-theme
 */

$wpstream_get_post_type = $post->post_type;
$author_id              = wpstream_get_author_id( $post->ID );
$use_transient          = wpstream_theme_return_use_transient();
$transient_key          = 'wpstream_related_content_' . $post->ID;
$current_post_terms     = wp_get_post_terms( $post->ID, 'wpstream_category', array( 'fields' => 'ids' ) );

$related_product_query_args = array(
	'post_type'      => $wpstream_get_post_type,
	'posts_per_page' => 4,
	'orderby'        => 'date', // Order by post date.
	'order'          => 'DESC', // Sort in descending order (latest first).
	'post__not_in'   => $post->ID,
	//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
	'tax_query'      => array(
		array(
			'taxonomy' => 'wpstream_category',
			'field'    => 'term_id',
			'terms'    => $current_post_terms,
			'operator' => 'IN', // You can use 'AND' to match posts that have all terms.
		),
	),
);

$query = wpstream_theme_custom_query( $related_product_query_args, $transient_key, $use_transient );
?>

<?php if ( $query->found_posts > 0 ) : ?>
	<section class="wpstream_section wpstream_related_product">
		<div class="<?php echo esc_attr( wpstream_theme_container_class() ); ?>">
			<div class="wpstream-grid-main">
				<h2 class="title-more">

					<?php
					// Section Title.
					echo esc_html( $wpstream_section_title ?? '' );
					?>

					
				</h2>
				<div class="row">
					<?php
					// The query to display results.
					include get_template_directory() . '/template-parts/single/video-loop-content.php';
					?>
				</div>
			</div>
		</div>
	</section>
<?php endif; ?>