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 "vocabulary.my-voc" (from myGroup)
AssetVocabulary vocabulary = AssetVocabularyLocalServiceUtil.getGroupVocabulary(myGroup.getGroupId(), "vocabulary.my-voc");

// Get all categories from vocabulary "vocabulary.my-voc"
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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s