Show related courses in single course page

Please add the given code in your wplms-customizer.php file at the end and before “?>” in wplms customizer plugin :

add_action('bp_after_course_body','wplms_modern_course_front_default');
function wplms_modern_course_front_default(){
?>
<div class="related_courses">
<h2><?php _e('Related Courses','wplms_modern');?></h2>
<?php
$terms = wp_get_post_terms(get_the_ID(),'course-cat');
$categories = array();
if(!empty($terms)){
foreach($terms as $term)
$categories[] = $term->term_id;
}
$args = apply_filters('wplms_moern_related_courses',array(
'post_type' => 'course',
'posts_per_page'=>3,
'post__not_in'=>array(get_the_ID()),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'course-cat',
'field' => 'id',
'terms' => $categories,
),
),
));
$args = apply_filters('wplms_carousel_course_filters',$args);
$courses = new WP_Query($args);

if($courses->have_posts()):
?>
<ul class="row">
<?php 
while($courses->have_posts()): $courses->the_post();
global $post;
echo '<li class="col-md-4">';

if(empty($style))
$style = 'course';

echo thumbnail_generator($post,$style,'medium');
echo '</li>';
endwhile;
?>
</ul>
<?php
else:
?>
<div class="message">
<p><?php _e('No related courses found','vibe');?></p>
</div>
<?php
endif;
wp_reset_postdata();
?>
</div>
<?php
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *