• Resolved keithghrobertson

    (@keithghrobertson)


    Hi,

    I’m wondering if there is a PHP function that will get the user’s group ID or name?

    Example:

    $user_id = 15;
    
    $user_group_id = get_cluevo_user_group($user_id);

    Thank you for a wonderful plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author eliasatcluevo

    (@eliasatcluevo)

    Hi,

    thank you for reaching out and your kind words. I will try to help you but our lead developer Chris is not available at the moment so I am sure there is a better solution then what I can come up with and maybe this thread gets an update when he is back :).
    I was not able to find a fitting hook or function that does what you need, but if you are comfortable querying the database directly you could try something like this:

    function get_grouplist_by_user_id($userId){
    	global $wpdb;
    	$userToGroups = $wpdb->prefix . CLUEVO_DB_TABLE_USERS_TO_GROUPS;
    	$wpUser = $wpdb->prefix . 'users';
    	$query = $wpdb->prepare(
    		"SELECT ug.group_id FROM $userToGroups ug JOIN $wpUser u ON ug.user_id = u.ID WHERE ug.user_id = %s",
    		$userId
    	);
    	$groupList = $wpdb->get_results($query);
    	return $groupList;
    }

    notice: a user can be in multiple groups

    I hope this helps and all the best,
    Elias

    Thread Starter keithghrobertson

    (@keithghrobertson)

    This is incredibly useful – thank you Elias!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is there a PHP function to get the user’s group id or name?’ is closed to new replies.