Get users by taxonomy category

Ektron’s taxonomy feature allows you to categorise not only content but also users and user groups too. Putting a user into a category has all kinds of uses such as identifying users who have performed a certain task on your site like signing up to a feature or adding something to their profile.

There is a little bit of a grey area in terms of whether you would use a user group or custom user properties for some of the use cases. Taxonomy is always going to be the more powerful option as it provides a hierarchical structure whereas groups and properties are flat.  Taxonomies themselves can also be extended through the use of custom properties on the category.

So consider what you will use it for before you go ahead and choose the right approach.

Here is a simple code sample:

// Use the Framework API from versions 8.5 onwards
Ektron.Cms.Framework.User.UserManager uMgr = new Ektron.Cms.Framework.User.UserManager();
Ektron.Cms.User.UserTaxonomyCriteria criteria = new Ektron.Cms.User.UserTaxonomyCriteria();

// Get users based on taxonomy ID
//criteria.AddFilter(Ektron.Cms.User.UserTaxonomyProperty.Id, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, 98);

// Or get users based on Taxonomy Path
criteria.AddFilter(Ektron.Cms.User.UserTaxonomyProperty.Path, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo,
"\\UserTax");

List userList = uMgr.GetList(criteria);

Response.Write(userList.Count().ToString());

The above code uses the Ektron Framework API to get the information so you will need to be using Ektron version 8.5 or greater.

Leave a comment