Search.../

listPosts( )

Retrieves a list of published posts.

Description

The listPosts() function returns a Promise that resolves to a list of up to 100 published posts.

Using the options parameter, you can filter your list of posts, set the amount of posts to be returned, and sort your list in a specified order.

By default, the list is sorted by firstPublishedDate in descending order, and the amount of posts returned is 50.

Syntax

function listPosts(options: ListPostsOptions): Promise<ListPostsResponse>

listPosts Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListPostsOptions

Sort, filter, and paging options.

Returns

Fulfilled - List of retrieved posts.

Return Type:

Promise<
ListPostsResponse
>
NAME
TYPE
DESCRIPTION
metaData
MetaData

Details on the paged set of results returned.

posts
Array<
Post
>

List of posts.

Was this helpful?

List posts from a blog

Copy Code
1import { posts } from 'wix-blog-backend';
2
3export async function listPostsFunction() {
4 try {
5 const result = await posts.listPosts();
6 const firstPostTitle = result.posts[0].title;
7 const firstPostExcerpt = result.posts[0].excerpt;
8 console.log('Retrieved Result:', result);
9 return result;
10 } catch (error) {
11 console.error(error);
12 }
13}
14
15
16/* Promise resolves to:
17 * {
18 * "posts": [
19 * {
20 * "_id": "0a265609-e16e-4c96-b71a-2a62b513e6c8",
21 * "categoryIds": [],
22 * "commentingEnabled": true,
23 * "excerpt": "some text",
24 * "featured": false,
25 * "firstPublishedDate": "2022-05-25T13:56:19.023Z",
26 * "hashtags": [],
27 * "heroImage": ""
28 * "language": "en",
29 * "lastPublishedDate": "2022-05-25T13:56:19.023Z",
30 * "media": {
31 * "wixMedia": {
32 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"
33 * },
34 * "displayed": true,
35 * "custom": false
36 * },
37 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",
38 * "minutesToRead": 1,
39 * "pinned": false,
40 * "preview": false,
41 * "pricingPlanIds": [],
42 * "relatedPostIds": [],
43 * "slug": "_new-post",
44 * "tagIds": [],
45 * "title": "new post",
46 * "translationId": ""
47 * },
48 * {
49 * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00",
50 * "categoryIds": [
51 * "1ea22fce-bc3c-4b78-9422-f0f367f8628e"
52 * ],
53 * "commentingEnabled": true,
54 * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....",
55 * "featured": true,
56 * "firstPublishedDate": "2020-08-05T21:00:00.000Z",
57 * "hashtags": [
58 * "sea",
59 * "sun"
60 * ],
61 * "heroImage": ""
62 * "language": "en",
63 * "lastPublishedDate": "2020-08-05T21:00:00.000Z",
64 * "media": {
65 * "wixMedia": {
66 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"
67 * },
68 * "displayed": true,
69 * "custom": false
70 * },
71 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",
72 * "minutesToRead": 1,
73 * "moderationDetails": {},
74 * "pinned": false,
75 * "pricingPlanIds": [
76 * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37"
77 * ],
78 * "relatedPostIds": [
79 * "425a5dca-c32d-40e6-b2d7-a8ffa3addded"
80 * ],
81 * "slug": "my-vacation",
82 * "tagIds": [
83 * "b698f939-cab5-419b-9966-ba0fa3316de9"
84 * ],
85 * "title": "My vacation",
86 * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b"
87 * }
88 * ],
89 * "metaData": {
90 * "count": 2,
91 * "offset": 0,
92 * "total": 2
93 * }
94 * }
95*/
List posts from a blog with filter, sorting and paging options

This example uses the options parameter to filter, sort, and page the posts from a blog.

Copy Code
1import { posts } from 'wix-blog-backend';
2
3/* Sample options values:
4 * {
5 * featured: false,
6 * categoryIds: [
7 * '6270ef2f8586e65a5e1047bc'
8 * ],
9 * sort: 'PUBLISHED_DATE_ASC',
10 * paging: {
11 * limit: 2
12 * }
13 * }
14 */
15
16
17export async function listPostsFunction(options) {
18 try {
19 const result = await posts.listPosts(options);
20 const firstPostTitle = result.posts[0].title;
21 const firstPostMemberId = result.posts[0].memberId;
22 console.log('Retrieved Result:', result);
23 return result;
24 } catch (error) {
25 console.error(error);
26 }
27}
28
29
30/*
31 * {
32 * "posts": [
33 * {
34 * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00",
35 * "categoryIds": [
36 * "1ea22fce-bc3c-4b78-9422-f0f367f8628e"
37 * ],
38 * "commentingEnabled": true,
39 * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....",
40 * "featured": true,
41 * "firstPublishedDate": "2020-08-05T21:00:00.000Z",
42 * "hashtags": [
43 * "sea",
44 * "sun"
45 * ],
46 * "heroImage": ""
47 * "language": "en",
48 * "lastPublishedDate": "2020-08-05T21:00:00.000Z",
49 * "media": {
50 * "wixMedia": {
51 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"
52 * },
53 * "displayed": true,
54 * "custom": false
55 * },
56 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",
57 * "minutesToRead": 1,
58 * "moderationDetails": {},
59 * "pinned": false,
60 * "preview": false,
61 * "pricingPlanIds": [
62 * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37"
63 * ],
64 * "relatedPostIds": [
65 * "425a5dca-c32d-40e6-b2d7-a8ffa3addded"
66 * ],
67 * "slug": "my-vacation",
68 * "tagIds": [
69 * "b698f939-cab5-419b-9966-ba0fa3316de9"
70 * ],
71 * "title": "My vacation",
72 * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b",
73 * "contentId": "62a9b7a4f276b0918225d8ef",
74 * "internalCategoryIds": [],
75 * "internalRelatedPostIds": [],
76 * "mostRecentContributorId": "33d02592-dd28-4eff-9b8e-4c3bb9c737dd"
77 * },
78 * {
79 * "_id": "78e6908f-87c6-4ddc-bc7f-c3150034d80d",
80 * "categoryIds": [
81 * "1ea22fce-bc3c-4b78-9422-f0f367f8628e"
82 * ],
83 * "commentingEnabled": true,
84 * "excerpt": "Let's talk about choosing best peppers for amazing peppercorn sauce",
85 * "featured": false,
86 * "firstPublishedDate": "2021-03-18T11:43:39.408Z",
87 * "hashtags": [],
88 * "heroImage": "",
89 * "language": "en",
90 * "lastPublishedDate": "2021-03-18T11:43:39.408Z",
91 * "media": {
92 * "wixMedia": {
93 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"
94 * },
95 * "displayed": true,
96 * "custom": false
97 * },
98 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",
99 * "minutesToRead": 1,
100 * "moderationDetails": {},
101 * "pinned": false,
102 * "pricingPlanIds": [],
103 * "relatedPostIds": [],
104 * "slug": "best-peppers-for-peppercorn-sauce",
105 * "tagIds": [
106 * "b698f939-cab5-419b-9966-ba0fa3316de9"
107 * ],
108 * "title": "Best peppers for peppercorn sauce",
109 * "translationId": "",
110 * "coverMedia": {
111 * "enabled": true,
112 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773",
113 * "displayed": true,
114 * "custom": false
115 * },
116 * "contentId": "6271a1618586e65a5e1064db",
117 * "coverMedia": {
118 * "enabled": true,
119 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773",
120 * "displayed": true,
121 * "custom": false
122 * },
123 * "internalCategoryIds": [],
124 * "internalRelatedPostIds": [],
125 * "mostRecentContributorId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea"
126 * }
127 * ],
128 * "metaData": {
129 * "count": 2,
130 * "offset": 0,
131 * "total": 4
132 * }
133 * }
134 */