mycred_count_ref_instances

Description

Returns the number of times a specific reference occurs in the log, with the option to filter by user ID or by point type.

Remember that transfers always have two log entries, one for the sender and one for the recipient. If you do not filter by a user ID, transfer counts will always be double!

Available since version 1.5.3

Returns

(int) Returns the number of found records.

Parameters

Param Type Required Description
function mycred_count_ref_instances(
$reference string Yes

The reference to count.

$user_id int No

Option to filter the count by a user ID.

$type string No

Option to filter results by a particular point type.

) { ... }

Examples

Example 1: Count the number of times a user has received points for approved comments.

$user_id = 1;
$count   = mycred_count_ref_instances( 'approved_comment', $user_id );

Example 2: Count the number of times points have been spent on paying for a WooCommerce order.

$payments = mycred_count_ref_instances( 'woocommerce_payment' );