dozent_get_instructors( array $args = array() )

Search instructors by passing search term


Description

Pass $limit parameter value = "-1" to get no limit at the search

Example usage:

 $args = array(
     $args = 'search_term'   => '',
     'not_in_ids'      => [],
     'start'         => 0,
     'per_page'      => 10,
 )

$instructors = dozent_get_instructors( $args );

Check the default arguments


Parameters

$args

(array) (Optional)

Default value: array()


Return

(object)


Source

File: includes/core-functions.php

	function dozent_get_instructors( $args = [] ) {
		global $wpdb;

		$defaults = apply_filters( 'dozent_get_instructors_default_args', [
			'search_term'   => '',
			'not_in_ids'      => [],
			'start'         => 0,
			'per_page'      => 10,
		] );

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

		$response = [
			'count'   => 0,
			'results' => null,
		];

		$not_in_ids_query = '';
		if ( ! empty($not_in_ids) && dozent_count( $not_in_ids ) ){
			$not_in_ids_string = implode( ",", $not_in_ids );
			$not_in_ids_query = " AND {$wpdb->users}.ID NOT IN( $not_in_ids_string ) ";
		}

		$limit_query = '';
		if ( $per_page !== '-1' ) {
			$limit_query = " LIMIT {$start}, {$per_page}  ";
		}

		if ( $search_term ) {
			$search_term
				= " AND ( {$wpdb->users}.display_name LIKE '%{$search_term}%' OR {$wpdb->users}.user_nicename LIKE '%{$search_term}%' OR {$wpdb->users}.user_email LIKE '%{$search_term}%' ) ";
		}

		$count = (int) $wpdb->get_var( "SELECT COUNT({$wpdb->users}.ID) FROM {$wpdb->users} 
			INNER JOIN {$wpdb->usermeta} 
			ON ( {$wpdb->users}.ID = {$wpdb->usermeta}.user_id ) 
			WHERE 1=1 AND ( {$wpdb->usermeta}.meta_key = '_dozent_instructor' )  {$search_term} $not_in_ids_query ;" );

		if ( $count ) {

			$results = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS {$wpdb->users}.* FROM {$wpdb->users} 
			INNER JOIN {$wpdb->usermeta} 
			ON ( {$wpdb->users}.ID = {$wpdb->usermeta}.user_id ) 
			WHERE 1=1 AND ( {$wpdb->usermeta}.meta_key = '_dozent_instructor' )  {$search_term} $not_in_ids_query
			ORDER BY user_registered DESC {$limit_query} " );

			$response = [
				'count'   => $count,
				'results' => $results,
			];

		}

		return (object) $response;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.