-
Notifications
You must be signed in to change notification settings - Fork 12
/
related-by-custom-taxonomy-and-cpt.php
37 lines (37 loc) · 1.15 KB
/
related-by-custom-taxonomy-and-cpt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/*
Insert to single-{cpt}.php
Author: https://levantoan.com
*/
$categories = get_the_terms(get_the_ID(), 'video_category');
if ($categories && is_array($categories)){
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'post__not_in' => array(get_the_ID()),
'post_type' => 'videos',
'posts_per_page' => 8,
'tax_query' => array(
array(
'taxonomy' => 'video_category',
'field' => 'term_id',
'terms' => $category_ids,
)
)
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ):
echo '<div class="relatedcat_videos">';
echo '<h3>Video liên quan</h3><div class="row">';
while ($my_query->have_posts()):$my_query->the_post();
?>
<div class="col-sm-3 col-xs-6">
<?php get_template_part('content', 'video');?>
</div>
<?php
endwhile;
echo '</div>';
echo '</div>';
endif; wp_reset_query();
}
?>