> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: getPostBySlug(slug: string, options: GetPostBySlugOptions) # Method package: wixBlogBackend # Method menu location: wixBlogBackend --> posts --> getPostBySlug # Method Link: https://dev.wix.com/docs/velo/apis/wix-blog-backend/posts/get-post-by-slug.md # Method Description: Gets a post by the provided slug. The `getPostBySlug()` function returns a Promise that resolves to a post whose slug matches the given slug. The `slug` is the end of a post's URL that refers to a specific post. For example, if a post's URL is `https:/example.com/blog/post/my-post-slug`, the slug is `my-post-slug`. The slug is case-sensitive, and is generally derived from the post title, unless specified otherwise. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Get a post by its slug ```javascript import { posts } from 'wix-blog-backend'; /* Sample slug value: * 'my-slug' */ export async function getPostBySlugFunction(slug) { try { const result = await posts.getPostBySlug(slug); const title = result.post.title; const postId = result.post._id; console.log('Retrieved Result:', result); return result; } catch (error) { console.error(error); } } /* Promise resolves to: * { * "post": { * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00", * "categoryIds": [ * "1ea22fce-bc3c-4b78-9422-f0f367f8628e" * ], * "commentingEnabled": true, * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....", * "featured": true, * "firstPublishedDate": "2020-08-05T21:00:00.000Z", * "hashtags": [ * "sea", * "sun" * ], * "heroImage": "" * "language": "en", * "lastPublishedDate": "2020-08-05T21:00:00.000Z", * "media": { * "wixMedia": { * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773" * }, * "displayed": true, * "custom": false * }, * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea", * "minutesToRead": 1, * "moderationDetails": {}, * "pinned": false, * "preview": false, * "pricingPlanIds": [ * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37" * ], * "relatedPostIds": [ * "425a5dca-c32d-40e6-b2d7-a8ffa3addded" * ], * "slug": "my-vacation", * "tagIds": [ * "b698f939-cab5-419b-9966-ba0fa3316de9" * ], * "title": "My vacation", * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b" * } * } */ ``` ## Get a post by its slug (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { posts } from 'wix-blog-backend'; /* Sample slug value: * 'my-slug' */ export const getPostBySlugFunction = webMethod(Permissions.Anyone, async (slug) => { try { const result = await posts.getPostBySlug(slug); const title = result.post.title; const postId = result.post._id; console.log('Retrieved Result:', result); return result; } catch (error) { console.error(error); } }); /* Promise resolves to: * { * "post": { * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00", * "categoryIds": [ * "1ea22fce-bc3c-4b78-9422-f0f367f8628e" * ], * "commentingEnabled": true, * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....", * "featured": true, * "firstPublishedDate": "2020-08-05T21:00:00.000Z", * "hashtags": [ * "sea", * "sun" * ], * "heroImage": "" * "language": "en", * "lastPublishedDate": "2020-08-05T21:00:00.000Z", * "media": { * "wixMedia": { * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773" * }, * "displayed": true, * "custom": false * }, * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea", * "minutesToRead": 1, * "moderationDetails": {}, * "pinned": false, * "preview": false, * "pricingPlanIds": [ * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37" * ], * "relatedPostIds": [ * "425a5dca-c32d-40e6-b2d7-a8ffa3addded" * ], * "slug": "my-vacation", * "tagIds": [ * "b698f939-cab5-419b-9966-ba0fa3316de9" * ], * "title": "My vacation", * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b" * } * } */ ``` ## Get a post by slug with additional fields ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { posts } from 'wix-blog-backend'; /* Sample slug value: * 'my-slug' * Sample options value: * { * fieldsets: [ * 'URL', * 'CONTENT_TEXT' * ] * } */ export const getPostBySlugFunction = webMethod(Permissions.Anyone, async (slug, options) => { try { const result = await posts.getPostBySlug(slug, options); const title = result.post.title; const postId = result.post._id; console.log('Retrieved Result:', result); return result; } catch (error) { console.error(error); } }); /* Promise resolves to: * { * "post": { * "_id": "ccbb6257-ed0e-4521-97df-8b5b207adb00", * "categoryIds": [ * "1ea22fce-bc3c-4b78-9422-f0f367f8628e" * ], * "commentingEnabled": true, * "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", * "excerpt": "Create a blog post subtitle that summarizes your post in a few short, punchy sentences and entices your audience to continue reading....", * "featured": true, * "firstPublishedDate": "2020-08-05T21:00:00.000Z", * "hashtags": [ * "sea", * "sun" * ], * "heroImage": "" * "language": "en", * "lastPublishedDate": "2020-08-05T21:00:00.000Z", * "media": { * "wixMedia": { * "image": "wix:image://v1/75059a_9f8cd2f1282c4dc7ae9a4bea155e2661~mv2.jpg#originWidth=602&originHeight=773" * }, * "displayed": true, * "custom": false * }, * "memberId": "4b9f4b64-0792-481e-9289-b2550c1bb7ea", * "minutesToRead": 1, * "moderationDetails": {}, * "pinned": false, * "preview": false, * "pricingPlanIds": [ * "b6e94a0c-4d0f-435e-9602-0dd61d2aca37" * ], * "relatedPostIds": [ * "425a5dca-c32d-40e6-b2d7-a8ffa3addded" * ], * "slug": "my-vacation", * "tagIds": [ * "b698f939-cab5-419b-9966-ba0fa3316de9" * ], * "title": "My vacation", * "translationId": "3cd710b7-c28d-4547-9b8a-3c1ec776064b", * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/post/my-vacation" * } * } */ ``` ---