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<Post>

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<
Post
>
NAME
TYPE
DESCRIPTION
_id
string

Post ID.

categoryIds
Array<
string
>

Category IDs of the post.

commentingEnabled
boolean

Whether commenting on the post is enabled.

contactId
string

Post owner's contact ID.

content
string

Reserved for internal use.

contentId
string

Reserved for internal use.

contentText
string

The post's content in plain text.

coverMedia
CoverMedia

Reserved for internal use.

excerpt
string

Post excerpt. Can be selected by a site contributor. By default, it is extracted from the content text's first characters.

Max: 140 characters

featured
boolean

Whether the post is marked as featured.

firstPublishedDate
Date

Date the post was first published.

hasUnpublishedChanges
boolean

Indicates if there is a draft post with changes that have not yet been published.

hashtags
Array<
string
>

Hashtags in the post.

heroImage
string

Image placed at the top of the blog page. Only displays on mobile devices.

internalCategoryIds
Array<
string
>

Reserved for internal use.

internalId
string

Reserved for internal use.

internalRelatedPostIds
Array<
string
>

Reserved for internal use.

language
string

Language the post is written in.

2-letter language code in ISO 639-1 alpha-2 format.

lastPublishedDate
Date

Date the post was last published.

media
BlogMedia

Post cover media.

memberId
string

Post owner's member ID.

minutesToRead
number

Estimated reading time.

moderationDetails
ModerationDetails

Post moderation details.

Only relevant to posts submitted by guest writers. Guest writers have the ability to write posts but not publish them. These posts can be rejected or approved for publishing by a blog editor or site owner.

mostRecentContributorId
string

Reserved for internal use.

pinned
boolean

Whether the post is pinned. If true, the post is placed at the top of the post list.

preview
boolean

Whether the returned content is a preview of premium content. Defaults to false. A preview displays a limited number of paragraphs of paid content to non-subscribed users.

pricingPlanIds
Array<
string
>

Pricing plan IDs.

If a post is assigned to a specific pricing plan.

relatedPostIds
Array<
string
>

IDs of posts related to the post.

richContent
RichContent

Post rich content

richContentString
string

Post rich content as a string

seoData
SeoSchema

SEO data.

slug
string

Part of a post's URL that refers to a specific post.

For example, 'https:/example.com/posts/my-post-slug'.

tagIds
Array<
string
>

IDs of tags the post is tagged with.

title
string

Post title.

translationId
string

ID of the post's translations when Wix Multilingual is installed on a site. All translations of a single post will share the same translationId.

url
string

Post URL.

Was this helpful?

Get a post by ID

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