<?php

$style = kanews_get_option('related-posts-style') ? kanews_get_option('related-posts-style') : 3; 
if(get_post_meta( $post->ID, 'show_posts_related', true ) != 'off') {
if($style != 'disable'):

$related_count = 10;
$sortby = kanews_get_option('related-posts-sortby') ? kanews_get_option('related-posts-sortby') : 'random';
$tags = wp_get_post_terms( get_queried_object_id(), 'post_tag', ['fields' => 'ids'] );
$categories = get_the_category($post->ID); if ($categories) {$category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;}

$post_not_in = isset($GLOBALS['related_post_not_in']) && $GLOBALS['related_post_not_in'] != '' ? $GLOBALS['related_post_not_in'] : array($post->ID);

if( $sortby == 'tag' )
$cats = '';
else
$tags = '';

global $post;
$current_post_id = $post->ID;

$query_args = array(
  'number'				=> $related_count,
  'cats'    		  => $category_ids,
  'sortby' 				=> $sortby,
  'exclude'    		=> $post_not_in,
  // 'tags_ids'      => $tags,

  'format'        => 'video',
);
$kanews_query = kan_query( $query_args );


if ($kanews_query->have_posts()) : ?>


<div class="kanews-section kanews-section-flat">


        <?php while($kanews_query->have_posts()): $kanews_query->the_post(); global $post; ?>
        <div class="kanews-post-item kanews-post-small-item">
      <a href="<?php the_permalink(); ?>" class="kanews-post-href" aria-label="<?php the_title(); ?>"></a>	
      <?php kanews_post_thumbnail('thumbnail', 'kanews-post-thumb'); ?>
      <div class="kanews-post-content">
        
        <?php the_title( sprintf( '<h3 class="kanews-post-headline truncate truncate-2"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' ); ?>
        <?php echo kanews_post_date('post', 'span'); ?>
      </div>
    </div>
        <?php 
        Kanews\Helper::do_not_dublicate( $post->ID );
        endwhile; wp_reset_postdata(); ?>


  </div>  
<?php 
else:
  echo esc_html__( 'Bulunamadı..', 'kanews' );
endif;
endif;
}