dozent_get_total_courses_by_instructor( $instructor,  $args = array() )

Return total course count by an instructor


Description

Pass $instructor | $user as first param and $course as second param to get the total course count.

Example usage:

dozent_get_total_courses_by_instructor( $instructor );

See also


Parameters

$instructor

(Required) $user->ID | user object user field


Return

(mixed|void)


Source

File: includes/user-functions.php

	function dozent_get_total_courses_by_instructor( $instructor, $args = [] ) {
		global $wpdb;

		$instructor = dozent_get_the_user( $instructor );

		$defaults = apply_filters( 'dozent_get_courses_by_instructor_default_args', [
			'course_status' => [ 'publish' ],
		] );

		$r = wp_parse_args( $args, $defaults );
		extract( $r, EXTR_SKIP );

		/**
		 * In course status SQL
		 */
		$in_sql       = "";
		if ( ! empty( $course_status ) ) {
			$where_in_sql = dozent_array_to_in_sql( $course_status );
			if ( $where_in_sql ) {
				$in_sql = " AND courses.post_status IN($where_in_sql) ";
			}
		}

		$course_count = (int) $wpdb->get_var( "SELECT COUNT(courses.ID) 
		FROM {$wpdb->dozent_instructor_courses} instructor_courses
		INNER JOIN {$wpdb->posts} courses ON instructor_courses.course_id = courses.ID
		WHERE instructor_courses.instructor_id = {$instructor->ID} {$in_sql} ;" );

		/**
		 * Filter the return of dozent_get_total_courses_by_instructor() function
		 *
		 * @since Dozent LMS v.1.0.0
		 */

		return apply_filters( 'dozent_get_total_courses_by_instructor', $course_count, $instructor );

	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.