llms_get_object_total_favorites( bool|int $object_id = false )

Get Favorites Count.


Parameters Parameters

$object_id

(bool|int) (Optional) WP Post ID of the Lesson. If not supplied it will default to the current post ID.

Default value: false


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/functions/llms.functions.favorite.php

function llms_get_object_total_favorites( $object_id = false ) {

	global $wpdb;

	// Getting ID from Global Post object.
	if ( ! $object_id ) {
		$object_id = get_the_ID();
	}

	$res = $wpdb->get_var(
		$wpdb->prepare(
			"SELECT COUNT(DISTINCT meta_id) FROM {$wpdb->prefix}lifterlms_user_postmeta
				WHERE post_id = %d AND meta_key = %s ORDER BY updated_date DESC",
			$object_id,
			'_favorite'
		)
	); // db call ok; no-cache ok.

	return $res;

}


Top ↑

Changelog Changelog

Changelog
Version Description
7.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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