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