mycred_get_badge_references

Description

This function will return an associative array of references and badge IDs that exists on your website. This function is mainly used for quick checks if a particular reference has badges associated with it.

This function is only available if the Badges add-on is enabled.

Available since version 1.7

Returns

(array) Associative array of references and the badge post object IDs belonging to each reference.

Parameters

Param Type Required Description
function mycred_get_badge_references(
$point_type string No

Option to query badges for a particular point type. Defaults to the main point type.

$force bool No

By default, badge references are cached to minimize database queries. This cache is reset each time you save a badge but you can use this parameter to force a new query, which in turn will reset the current cached results.

) { ... }

Examples

Example 1: Check if the reference “approved_comment“ exists among published badges.

$reference  = 'approved_comment';
$badge_refs = mycred_get_badge_references();

if ( ! empty( $badge_refs ) && array_key_exists( $reference, $badge_refs ) ) {

	// Values are always an array since a reference might exists
	// in more than one badge
	$badge_ids = $badge_refs[ $reference ];

}