I have created a site where new users are required to create a new group. I'm working with the rules module and I want to create a condition where by if the current user has not yet created a group, they are redirected to a certain page.

So my question is, what php snippet would return either the number of groups created by the current user, or a true/false value based on whether the current user has created a group or not.

Comments

Grayside’s picture

Status: Active » Fixed
global $user;
$count = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE uid=%d AND type='%s'", $user->uid, 'group-type-name'));

That should be enough to get you going.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

amitaibu’s picture

Generally, it's better to user_load() the user so if it's cached already you don't hit the db again.

Grayside’s picture

user_load() does not have a static cache in D6... yeah.