Improving Related course accuracy

The following tip will improve related course accuracy in modern theme.

Currently the Related courses pick the courses from the same category to which the current course is connected to. The relation between category and courses is “or”.

Following tip will identify if the course is connected to a child category, then it will use only the child category for listing out related courses.

Paste this code in Child theme – Functions.php or Wp admin – Plugins – Editor – Wplms customiser – wplms_customiser.php

add_filter('wplms_carousel_course_filters','wplms_related_course_child_category');
function wplms_related_course_child_category($args){
	global $post;
	$terms = wp_get_post_terms($post->ID,'course-cat');
	$categories = array();
	if(!empty($terms)){
		foreach($terms as $term){
			if(!empty($term->parent)){
				$categories[] = $term->term_id;
			}
		}
	}
	if(empty($categories)){
		return $args;		
	}
	$args['tax_query'][0]['terms'] = $categories;

	return $args;
}

 

 

Was this article helpful?

Related Articles

2 Comments

Leave A Comment?