Retrieves a list of categories.
The listCategories()
function returns a Promise that resolves to a list of up to 100 categories per language in order of their displayPosition
starting with 0
. The displayPosition
is the position in which the categories are displayed in the Category Menu page. By default, categories get added to the bottom of the Category Menu with a displayPosition
of -1
.
function listCategories(
options: ListCategoriesOptions,
): Promise<ListCategoriesResponse>;
Filter and paging options.
import { categories } from "wix-blog-backend";
export async function listCategoriesFunction() {
try {
const result = await categories.listCategories();
const firstCategoryLabel = result.categories[0].label;
const firstCategoryId = result.categories[0]._id;
console.log("Retrieved Result:", result);
return result;
} catch (error) {
console.error(error);
}
}
/* Promise resolves to:
* {
* "categories": [
* {
* "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
* "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
* "description": "my category description",
* "displayPosition": 0,
* "label": "My Category",
* "language": "en",
* "postCount": 1,
* "slug": "my-category",
* "title": "My Category",
* "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
* },
* {
* "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
* "description": "Posts about my summer",
* "displayPosition": 1,
* "label": "Summer",
* "language": "en",
* "postCount": 6,
* "slug": "summer-slug"
* "title": "My Category",
* "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de"
* },
* ],
* "metaData": {
* "count": 2,
* "offset": 0,
* "total": 2
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.