Skip to content

Instantly share code, notes, and snippets.

@Tanvir741
Created November 1, 2020 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tanvir741/097d2a471327840770eda0e74e4ab618 to your computer and use it in GitHub Desktop.
Save Tanvir741/097d2a471327840770eda0e74e4ab618 to your computer and use it in GitHub Desktop.
<Section class="detail-item">
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 left-sidebar" >
<?php function wpse_get_video_posts_with_matching_categories() {
$categories = get_the_category( get_the_ID() );
if ( empty ( $categories ) ) {
return;
}
$my_query = new WP_Query( [
'post__not_in' => [ get_the_ID() ],
'posts_per_page' => 30,
'tax_query' => [
'relation' => 'AND', // We will check BOTH of the following criteria.
[
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => [ 'post-format-video' ],
'operator' => 'IN',
],
[
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => wp_list_pluck( $categories, 'term_id' ), // A handy way to extract data.
'operator' => 'AND',
],
],
] );
?>
<?php if ( $my_query->have_posts() ) : ?>
<div class="sidebar">
<?php while( $my_query->have_posts() ) : ?>
<div class="col-md-4 col-sm-4 col-sm-6 col-xs-12" style="padding:10px;">
<div class="tab-p-container tab-p-hover">
<a href="<?php the_permalink();?>">
<div class=" <?php printf('%s', $video_thumb);?>">
<?php
if (has_post_thumbnail() ){
the_post_thumbnail('filmmaker_BE');
}else {
echo $image;
} ?>
</div>
</a>
</div>
<div class="tab-p-content">
<div class="tab-p-name">
<a href="<?php the_permalink();?>" title=""><?php echo wp_trim_words( get_the_title(), 6, '...' ); ?></a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
<?php } ?>
</div>
</div>
</div>
</Section>
<?php wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment