LLMS_Student::get_completed_courses( array $args = array() )

Retrieve IDs of courses a user has completed

Parameters Parameters


(array) (Optional) query arguments @arg int $limit number of courses to return @arg string $orderby table reference and field to order results by @arg string $order result order (DESC, ASC) @arg int $skip number of results to skip for pagination purposes

Default value: array()

Top ↑

Return Return

(array) "courses" will contain an array of course ids "more" will contain a boolean determining whether or not more courses are available beyond supplied limit/skip criteria

Top ↑

Source Source

File: includes/models/model.llms.student.php

	public function get_completed_courses( $args = array() ) {

		global $wpdb;

		$args = array_merge(
				'limit'   => 20,
				'orderby' => 'upm.updated_date',
				'order'   => 'DESC',
				'skip'    => 0,

		// Add one to the limit to see if there's pagination.

		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		$q = $wpdb->get_results(
				"SELECT upm.post_id AS id
			 FROM {$wpdb->prefix}lifterlms_user_postmeta AS upm
			 JOIN {$wpdb->posts} AS p ON p.ID = upm.post_id
			 WHERE p.post_type = 'course'
			   AND upm.meta_key = '_is_complete'
			   AND upm.meta_value = 'yes'
			   AND upm.user_id = %d
			 ORDER BY {$args['orderby']} {$args['order']}
			 LIMIT %d, %d;
		); // db call ok; no-cache ok.
		// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		$ids  = array_keys( $q );
		$more = false;

		// If we hit our limit we have too many results, pop the last one.
		if ( count( $ids ) === $args['limit'] ) {
			array_pop( $ids );
			$more = true;

		// Reset args to pass back for pagination.

		$r = array(
			'limit'   => $args['limit'],
			'more'    => $more,
			'results' => $ids,
			'skip'    => $args['skip'],

		return $r;


Top ↑

Changelog Changelog

Version Description
?? Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.