Gets a tag by the specified slug.
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
.
function getTagBySlug(
slug: string,
options: GetTagBySlugOptions,
): Promise<GetTagBySlugResponse>;
Slug of the tag to retrieve.
Options specifying which additional fields to return.
import { tags } from "wix-blog-backend";
/* Sample slug value:
* 'my-tag'
*/
export async function getTagBySlugFunction(slug) {
try {
const result = await tags.getTagBySlug(slug);
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-05-03T10:10:49.499Z",
* "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",
* "_updatedDate": "2022-05-03T10:10:49.499Z",
* "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.