getTag( )
Gets a tag by the specified ID.
Description
The getTag()
function returns a Promise that resolves to a tag whose ID matches the specified ID.
Syntax
function getTag(tagId: string, options: GetTagOptions): Promise<Tag>
getTag Parameters
NAME
TYPE
DESCRIPTION
Tag ID.
Options specifying which additional fields to return.
Returns
Tag info.
Return Type:
NAME
TYPE
DESCRIPTION
Date the tag was created.
Tag ID.
Date the tag was last updated.
Tag label.
A blog can't have two tags with the same label.
Number of posts with this tag, including unpublished draft posts.
Reserved for internal use.
Number of published posts with this tag.
Part of a tag's URL that refers to a specific tag.
For example, 'https:/example.com/tags/{my-tag-slug}'
.
ID of the tag's translations when Wix Multilingual is installed on a site. All translations of a single tag will share the same translationId
.
Tag URL.
The url
directs you to a page that lists every post with the specified tag.
Was this helpful?
1import { tags } from 'wix-blog-backend';23/* Sample tagId value:4 * '32970480-e53b-46e7-b52f-fba810a0b45d'5 */67export async function getTagFunction(tagId) {8 try {9 const result = await tags.getTag(tagId);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-07-19T10:30:03.607Z",24 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",25 * "_updatedDate": "2022-07-19T10:30:03.607Z",26 * "label": "my tag",27 * "language": "en",28 * "postCount": 1,29 * "publishedPostCount": 1,30 * "slug": "my-tag",31 * "translationId": "32 * }33 * }34 */
1import { Permissions, webMethod } from 'wix-web-module';2import { tags } from 'wix-blog-backend';34/* Sample tagId value:5 * '32970480-e53b-46e7-b52f-fba810a0b45d'6 */78export const getTagFunction = webMethod(Permissions.Anyone, async (tagId) => {9 try {10 const result = await tags.getTag(tagId);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-07-19T10:30:03.607Z",25 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",26 * "_updatedDate": "2022-07-19T10:30:03.607Z",27 * "label": "my tag",28 * "language": "en",29 * "postCount": 1,30 * "publishedPostCount": 1,31 * "slug": "my-tag",32 * "translationId": "33 * }34 * }35 */
1import { Permissions, webMethod } from 'wix-web-module';2import { tags } from 'wix-blog-backend';34/* Sample tagId value:5 * '32970480-e53b-46e7-b52f-fba810a0b45d'6 *7 * Sample options value:8 * {9 * fieldsets:10 * [11 * 'URL'12 * ]13 * }14 */1516export const getTagFunction = webMethod(Permissions.Anyone, async (tagId, options) => {17 try {18 const result = await tags.getTag(tagId, options);19 const label = result.tag.label;20 const postCount = result.tag.postCount;21 const url = result.tag.url;22 console.log('Retrieved result:', result);23 return result;24 } catch (error) {25 console.error(error);26 }27});2829/* Promise resolves to:30 * {31 * "tag": {32 * "_createdDate": "2022-07-19T10:30:03.607Z",33 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",34 * "_updatedDate": "2022-07-19T10:30:03.607Z",35 * "label": "my tag",36 * "language": "en",37 * "slug": "my-tag",38 * "postCount": 1,39 * "publishedPostCount": 1,40 * "translationId": "",41 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/tags/my-tag"42 * }43 * }44 */