rcp_count_memberships()

Counts the number of memberships meeting the criteria.

Parameters:

  • $args (array) - Array of arguments, all of which are optional:
    • $id (int) - A membership ID to only return that membership. Default empty.
    • $id__in (array) - An array of membership IDs. Default empty.
    • $id__not_in (array) - An array of membership IDs to exclude from the results. Default empty.
    • $customer_id (int) - A customer ID to only return this customer's memberships. Default empty.
    • $customer_id__in (array) - An array of customer IDs to return memberships belonging to these customers. Default empty.
    • $customer_id__not_in (array) - An array of customer IDs to exclude their memberships. Default empty.
    • $object_id (int) - ID of a membership level to only return memberships of this level. Default empty.
    • $object_id__in (array) - An array of membership level IDs to only return memberships of these levels. Default empty.
    • $object_id__not_in (array) - An array of membership level IDs to exclude memberships of these levels. Default empty.
    • $object_type (string) - An object type to only return memberships of this type. Default empty.
    • $object_type__in (array) - An array of object types. Default empty.
    • $object_type__not_in (array) - An array of object types to exclude. Default empty.
    • $currency (string) - A currency code to only return memberships using this currency. Default empty.
    • $created_date_query (array) - Date query clauses to limit memberships by. See WP_Date_Query for supported formats. Default empty.
    • $trial_end_date_query (array) - Date query clauses to limit memberships by. See WP_Date_Query for supported formats. Default empty.
    • $cancellation_date_date_query (array) - Date query clauses to limit memberships by. See WP_Date_Query for supported formats. Default empty.
    • $expiration_date_query (array) - Date query clauses to limit memberships by. See WP_Date_Query for supported formats. Default empty.
    • $auto_renew (int) - Filter by auto renew status (1 for recurring, 0 for not recurring). Default null.
    • $status (string) - A status slug, to only return memberships with this status. Supports: pending, active, cancelled, expired. Default empty.
    • $status__in (array) - Array of status slugs to include. Default empty.
    • $status__not_in (array) - Array of status slugs to exclude. Default empty.
    • $gateway_customer_id (string) - A gateway customer ID. Default empty.
    • $gateway_subscription_id (string) - A gateway subscription ID. Default empty.
    • $gateway (string) - A gateway slug. Default empty.
    • $subscription_key (string) - A subscription key. Default empty.
    • $upgraded_from (int) - ID of a membership. This will return only memberships that were upgraded from this one. Default empty.
    • $disabled (int|null) - Whether to show all memberships (null), only enabled memberships (0), or only disabled memberships (1). Default 0.
    • $meta_query (array) - An array of meta query arguments arrays (an array of arrays).
    • $no_found_rows (bool) Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
    • $search (string) - Search term(s) to retrieve matching memberships for. This searches most of the above membership columns. Default empty.
    • $update_cache (bool) - Whether to prime the cache for found memberships. Default false.

Return values:

  • (int) - The number of results.

Examples:

Retrieve the number of active memberships:

$count = rcp_count_memberships( array(
    'status' => 'active'
) );

Retrieve the number of expired memberships that are on membership level #3:

$count = rcp_count_memberships( array(
    'object_id' => 3,
    'status' => 'expired'
) );

Retrieve the number of memberships that use the Stripe gateway:

$count = rcp_count_memberships( array(
    'gateway' => 'stripe'
) );

Retrieve the number of memberships expiring between December 1st and December 31st:

$count = rcp_count_memberships( array(
    'expiration_date' => array(
        'after' => date( '2018-12-01 00:00:00', current_time( 'timestamp' ) ),
        'before' => date( '2018-12-31 23:59:59', current_time( 'timestamp' ) ),
    )
) );

Retrieve the number of active memberships with the meta key "company" and value "Sandhills" :

$count = rcp_count_memberships( array(
    'status' => 'active',
    'meta_query' => array(
        array(
            'key' => 'company',
            'value' => 'Sandhills',
        )
    )
) );