Liferay 6: How to get categories from a vocabulary

Here is a simple snippet that let you get all categories from a vocabulary. A vocabulary is always pinned to a group (either a simple group or to the global group of a company).

// Get vocabulary "" (from myGroup)
AssetVocabulary vocabulary = AssetVocabularyLocalServiceUtil.getGroupVocabulary(myGroup.getGroupId(), "");

// Get all categories from vocabulary ""
List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getVocabularyCategories(vocabulary.getVocabularyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

NB: you can use method “getVocabularyRootCategories” to get the level-0 categories of your vocabulary.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.