mycred_get_total_by_time

Description

This function will return the total number of points logged in the log table between two dates, either in total, for a specific reference or for a specific user.

Available since version 1.1.1

Returns

(int | float) The total amount of points resulting from this query.

Parameters

Param Type Required Description
function mycred_get_total_by_time(
$from int or string No

A timestamp or keyword that indicates from what date/time we should start counting. Uses strtotime to convert a start date/time into a UNIX timestamp. Defaults to the keyword today.

$until int or string No

A timestamp or keyword that indicates the date/time where counting should end. Uses strtotime to convert a end date/time into a UNIX timestamp. Defaults to the keyword now.

$reference string No

Option to filter the query to sum up only entries of a particular reference.

$user_id int No

Option to filter the query to sum up only entries of a particular user.

$point_type string No

Option to filter the query to sum up only entries of a particular point type. Defaults to the default point type.

) { ... }

Examples

Example 1: Get the total amount of points that users have gained/lost from start of today until now

$total = mycred_get_total_by_time();

printf( 'A total of %d points have been gained today.', $total );

Example 2: Get the total amount of points that users have gained/lost from January 1st until November 30th.

$total = mycred_get_total_by_time( '2016-01-01', '2016-11-30' );

echo $total . ' points';

Example 3: Get the total amount of points that has been spent on WooCommerce order payments the last 7 days.

$total = mycred_get_total_by_time( '-1 week', 'now', 'woocommerce_payment' );

printf( 'A total of %d points have been spent in the store in the past 7 days', abs( $total ) );