mycred_get_users_badges
Description
This function returns an array badge IDs that a given user has earned.
This function is only available if the Badges add-on is enabled.
Available since version 1.5
Returns
(string | array) Returns either an array of post IDs or an empty string if the user ID provided is invalid.
Parameters
Param | Type | Required | Description | |
---|---|---|---|---|
function mycred_get_users_badges( |
||||
$user_id |
int | Yes | The users numeric ID. |
|
) { ... } |
Examples
Example 1: Count the number of badges the current user has earned
$user_id = get_current_user_id(); $badge_ids = mycred_get_users_badges( $user_id ); $badge_count = 0; if ( ! empty( $badge_ids ) ) $badge_count = count( $badge_ids );