Gets a tag by the specified ID.
The getTag()
function returns a Promise that resolves to a tag whose ID matches the specified ID.
function getTag(tagId: string, options: GetTagOptions): Promise<BlogTag>;
Tag ID.
Options specifying which additional fields to return.
import { tags } from "wix-blog-backend";
/* Sample tagId value:
* '32970480-e53b-46e7-b52f-fba810a0b45d'
*/
export async function getTagFunction(tagId) {
try {
const result = await tags.getTag(tagId);
const label = result.tag.label;
const postCount = result.tag.postCount;
console.log("Retrieved result:", result);
return result;
} catch (error) {
console.error(error);
}
}
/* Promise resolves to:
* {
* "tag": {
* "_createdDate": "2022-07-19T10:30:03.607Z",
* "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",
* "_updatedDate": "2022-07-19T10:30:03.607Z",
* "label": "my tag",
* "language": "en",
* "postCount": 1,
* "publishedPostCount": 1,
* "slug": "my-tag",
* "translationId": "
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.