Search...
getTagBySlug( )
Gets a tag by the specified slug.
Description
The getTagBySlug()
function returns a Promise that resolves to a tag whose slug matches the specified slug.
The slug
is the end of a tag's URL that refers to a specific tag. For example, if a tag's URL is https://example.com/blog/tag/{my-tag-slug}
, the slug is my-tag-slug
. The slug is case-sensitive and derived from the tag's label
.
Syntax
function getTagBySlug(slug: string, options: GetTagBySlugOptions): Promise<GetTagBySlugResponse>
getTagBySlug Parameters
NAME
TYPE
DESCRIPTION
slug
string
Slug of the tag to retrieve.
options
Optional
GetTagBySlugOptions
Options specifying which additional fields to return.
Returns
Return Type:
Promise<
GetTagBySlugResponse
>NAME
TYPE
DESCRIPTION
tag
Tag
Tag info.
Was this helpful?
Get a tag by its slug
Copy Code
1import { tags } from 'wix-blog-backend';23/* Sample slug value:4 * 'my-tag'5 */67export async function getTagBySlugFunction(slug) {8 try {9 const result = await tags.getTagBySlug(slug);10 const label = result.tag.label;11 const postCount = result.tag.postCount;12 console.log('Retrieved result:', result);13 return result;14 } catch (error) {15 console.error(error);16 }17}181920/* Promise resolves to:21 * {22 * "tag": {23 * "_createdDate": "2022-05-03T10:10:49.499Z",24 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",25 * "_updatedDate": "2022-05-03T10:10:49.499Z",26 * "label": "my-tag",27 * "language": "en",28 * "postCount": 1,29 * "publishedPostCount": 1,30 * "slug": "my-tag",31 * "translationId": ""32 * }33 * }34 */
Get a tag by its slug (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { tags } from 'wix-blog-backend';34/* Sample slug value:5 * 'my-tag'6 */78export const getTagBySlugFunction = webMethod(Permissions.Anyone, async (slug) => {9 try {10 const result = await tags.getTagBySlug(slug);11 const label = result.tag.label;12 const postCount = result.tag.postCount;13 console.log('Retrieved result:', result);14 return result;15 } catch (error) {16 console.error(error);17 }18});192021/* Promise resolves to:22 * {23 * "tag": {24 * "_createdDate": "2022-05-03T10:10:49.499Z",25 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",26 * "_updatedDate": "2022-05-03T10:10:49.499Z",27 * "label": "my-tag",28 * "language": "en",29 * "postCount": 1,30 * "publishedPostCount": 1,31 * "slug": "my-tag",32 * "translationId": ""33 * }34 * }35 */36
Get a tag by its slug with additional fields
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { tags } from 'wix-blog-backend';34/* Sample slug value:5 * 'my-tag'6 * Sample options value:7 * {8 * fieldsets:9 * [10 * 'URL'11 * ]12 * }13 */1415export const getTagBySlugFunction = webMethod(Permissions.Anyone, async (slug, options) => {16 try {17 const result = await tags.getTagBySlug(slug, options);18 const label = result.tag.label;19 const postCount = result.tag.postCount;20 const url = result.tag.url;21 console.log('Retrieved result:', result);22 return result;23 } catch (error) {24 console.error(error);25 }26});2728/* Promise resolves to:29 * {30 * "tag": {31 * "_createdDate": "2022-05-03T10:10:49.499Z",32 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",33 * "_updatedDate": "2022-05-03T10:10:49.499Z",34 * "label": "my-tag",35 * "language": "en",36 * "postCount": 1,37 * "publishedPostCount": 1,38 * "slug": "my-tag",39 * "translationId": "",40 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/tags/my-tag"41 * }42 * }43 */