Search...
getPost( )
Gets a post by the specified ID.
Description
The getPost()
function returns a Promise that resolves to a post whose ID matches the given ID.
Syntax
function getPost(postId: string, options: GetPostOptions): Promise<GetPostResponse>
getPost Parameters
NAME
TYPE
DESCRIPTION
postId
string
Post ID.
options
Optional
GetPostOptions
Options specifying which fields to return.
Returns
Fulfilled - The requested post.
Return Type:
Promise<
GetPostResponse
>NAME
TYPE
DESCRIPTION
post
Post
Post info.
Was this helpful?
Get a post by ID
Copy Code
1import { posts } from 'wix-blog-backend';23/* Sample postId value:4 * 'ccbb6257-ed0e-4521-97df-8b5b207adb00'5 */67export async function getPostFunction(postId) {8 try {9 const result = await posts.getPost(postId);10 const title = result.post.title;11 const excerpt = result.post.excerpt;12 console.log('Retrieved Result:', result);13 return result;14 } catch (error) {15 console.error(error);16 };17}181920/* Promise resolves to:21 * {22 * "post": {23 * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00",24 * "categoryIds": [25 * "1ea22fce-bc3c-4b78-9422-f0f367f8628e"26 * ],27 * "commentingEnabled": true,28 * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....",29 * "featured": true,30 * "firstPublishedDate": "2020-08-05T21:00:00.000Z",31 * "hashtags": [32 * "sea",33 * "sun"34 * ],35 * "heroImage": ""36 * "language": "en",37 * "lastPublishedDate": "2020-08-05T21:00:00.000Z",38 * "media": {39 * "wixMedia": {40 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"41 * },42 * "displayed": true,43 * "custom": false44 * },45 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",46 * "minutesToRead": 1,47 * "moderationDetails": {},48 * "pinned": false,49 * "preview": false,50 * "pricingPlanIds": [51 * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37"52 * ],53 * "relatedPostIds": [54 * "425a5dca-c32d-40e6-b2d7-a8ffa3addded"55 * ],56 * "slug": "my-vacation",57 * "tagIds": [58 * "b698f939-cab5-419b-9966-ba0fa3316de9"59 * ],60 * "title": "My vacation",61 * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b",62 * "contentId": "62a9b7a4f276b0918225d8ef"63 * }64 * }65 */
Get a post by ID (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { posts } from 'wix-blog-backend';34/* Sample postId value:5 * 'ccbb6257-ed0e-4521-97df-8b5b207adb00'6 */78export const getPostFunction = webMethod(Permissions.Anyone, async (postId) => {9 try {10 const result = await posts.getPost(postId);11 const title = result.post.title;12 const excerpt = result.post.excerpt;13 console.log('Retrieved Result:', result);14 return result;15 } catch (error) {16 console.error(error);17 };18});1920/* Promise resolves to:21 * {22 * "post": {23 * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00",24 * "categoryIds": [25 * "1ea22fce-bc3c-4b78-9422-f0f367f8628e"26 * ],27 * "commentingEnabled": true,28 * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....",29 * "featured": true,30 * "firstPublishedDate": "2020-08-05T21:00:00.000Z",31 * "hashtags": [32 * "sea",33 * "sun"34 * ],35 * "heroImage": ""36 * "language": "en",37 * "lastPublishedDate": "2020-08-05T21:00:00.000Z",38 * "media": {39 * "wixMedia": {40 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"41 * },42 * "displayed": true,43 * "custom": false44 * },45 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",46 * "minutesToRead": 1,47 * "moderationDetails": {},48 * "pinned": false,49 * "preview": false,50 * "pricingPlanIds": [51 * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37"52 * ],53 * "relatedPostIds": [54 * "425a5dca-c32d-40e6-b2d7-a8ffa3addded"55 * ],56 * "slug": "my-vacation",57 * "tagIds": [58 * "b698f939-cab5-419b-9966-ba0fa3316de9"59 * ],60 * "title": "My vacation",61 * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b",62 * "contentId": "62a9b7a4f276b0918225d8ef"63 * }64 * }65 */
Get a post by ID with additional fields
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { posts } from 'wix-blog-backend';34/* Sample postId value:5 * 'ccbb6257-ed0e-4521-97df-8b5b207adb00'6 *7 * Sample options value:8 * {9 * fieldsets: [10 * 'URL',11 * 'CONTENT_TEXT'12 * ]13 * }14 */1516export const getPostFunction = webMethod(Permissions.Anyone, async (postId, options) => {17 try {18 const result = await posts.getPost(postId, options);19 const title = result.post.title;20 const contentText = result.post.contentText;21 console.log('Retrieved Result:', result);22 return result;23 } catch (error) {24 console.error(error);25 }26});2728/* Promise resolves to:29 * {30 * "post": {31 * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00",32 * "categoryIds": [33 * "1ea22fce-bc3c-4b78-9422-f0f367f8628e"34 * ],35 * "commentingEnabled": true,36 * "contentText": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading. #sea #sun",37 * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....",38 * "featured": true,39 * "firstPublishedDate": "2020-08-05T21:00:00.000Z",40 * "hashtags": [41 * "sea",42 * "sun"43 * ],44 * "heroImage": ""45 * "language": "en",46 * "lastPublishedDate": "2020-08-05T21:00:00.000Z",47 * "media": {48 * "wixMedia": {49 * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773"50 * },51 * "displayed": true,52 * "custom": false53 * },54 * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea",55 * "minutesToRead": 1,56 * "moderationDetails": {},57 * "pinned": false,58 * "preview": false,59 * "pricingPlanIds": [60 * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37"61 * ],62 * "relatedPostIds": [63 * "425a5dca-c32d-40e6-b2d7-a8ffa3addded"64 * ],65 * "slug": "my-vacation",66 * "tagIds": [67 * "b698f939-cab5-419b-9966-ba0fa3316de9"68 * ],69 * "title": "My vacation",70 * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b",71 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/post/my-vacation"72 * }73 * }74 */