In Restrict Content Pro version 3.0 and higher, there is a "memberships" database table and a "membershipmeta" database table. The metatable allows you to add metadata to a membership. You can use the following functions to retrieve, add, update, and delete membership meta:
rcp_get_membership_meta()
Used to retrieve meta for a specific membership.
Parameters:
- $membership_id (int) - ID of the membership.
- $meta_key (string) - Optional. The meta key to retrieve. By default, returns data for all keys. Default empty.
- $single (bool) - Optional, default is false. If true, return only the first value of the specified meta_key. This parameter has no effect if meta_key is not specified.
rcp_add_membership_meta()
Add a metadata field to a membership.
Parameters:
- $membership_id (int) - ID of the membership.
- $meta_key (string) - Meta key name.
- $meta_value (mixed) - Metadata value. Must be serializable if non-scalar.
- $unique (bool) - Optional. Whether the same key should not be added. Default false.
rcp_update_membership_meta()
Update the membership meta field based on membership ID. If the meta field for the membership does not exist, it will be added.
Parameters:
- $membership_id (int) - ID of the membership.
- $meta_key (string) - Meta key name.
- $meta_value (mixed) - Meta data value. Must be serializable if non-scalar.
- $prev_value (mixed) - Optional. Previous value to check before removing. Default empty.
rcp_delete_membership_meta()
Remove meta data from a membership.
Parameters:
- $membership_id (int) - ID of the membership.
- $meta_key (string) - Meta key name.
- $meta_value (mixed) - Metadata value. Must be serializable if non-scalar. Default empty.
Using Meta Keys/Values In Queries
You can perform meta queries while using rcp_get_memberships(). The below query would search for all memberships with the meta key "company" and the value "Sandhills":
$memberships = rcp_get_memberships( array( 'number' => 9999, 'meta_query' => array( array( 'key' => 'company', 'value' => 'Sandhills', ) ) ) );