Repository navigation
Developer API
$groups = wp_get_terms_for_user( $user_id, 'user-group' );Accepts a user ID or an object with an ID property. It returns term objects
with object_id, or false when the user cannot be resolved.
wp_set_terms_for_user( $user_id, 'user-group', array( $term_id ) );The third argument is a complete replacement. Passing an empty array removes all relationships in that taxonomy. Use term IDs when possible; numeric strings can otherwise be interpreted as names by WordPress.
$names = wp_get_user_groups();
$objects = wp_get_user_group_objects();wp_get_user_groups( $args, $output, $operator ) wraps get_taxonomies() and
adds user_group => true. $output may be names or objects.
$users = wp_get_users_of_group(
array(
'taxonomy' => 'user-group',
'term' => 'editorial',
'term_by' => 'slug',
),
array(
'orderby' => 'display_name',
'order' => 'ASC',
)
);term_by accepts slug, name, id, or term_taxonomy_id. The second
argument accepts WP_User_Query arguments, but the plugin always limits the
query to users related to the requested term.
Because the plugin uses taxonomies, native APIs are also useful:
$term = get_term_by( 'slug', 'editorial', 'user-group' );
$ids = get_objects_in_term( $term->term_id, 'user-group' );Use the plugin helpers for membership operations because they normalize user objects and clean the appropriate object-term cache.
Documentation for WP User Groups · Support