queryTags( )
Creates a query to retrieve a list of tags.
Description
The queryTags()
function builds a query to retrieve a list of up to 4,000 tags per language, and returns a TagsQueryBuilder
object.
The returned object contains the query definition, which is typically used to run the query using the find()
function.
You can refine the query by chaining TagsQueryBuilder
functions onto the query. TagsQueryBuilder
functions enable you to sort, filter, and control the results that queryTags()
returns.
queryTags()
runs with these TagsQueryBuilder
defaults that can be overridden:
The following TagQueryBuilder
functions are supported for queryTags()
. For a full description of the Tags object, see the object returned for the items
property in TagsQueryResult
.
PROPERTY | SUPPORTED FILTERS & SORTING |
---|---|
_id | eq() ,ne() ,hasSome() |
label | eq() ,ne() ,startsWith() ,hasSome() ,exists() ,in() ,ascending() ,descending() |
slug | eq() ,ne() ,startsWith() ,hasSome() ,exists() ,in() ,ascending() ,descending() |
publicationCount | eq() ,ne() ,lt() ,le() ,gt() ,ge() ,in() ,ascending() ,descending() |
postCount | eq() ,ne() ,lt() ,le() ,gt() ,ge() ,in() ,ascending() ,descending() |
translationId | eq() ,ne() ,exists() ,in() |
language | eq() ,ne() ,exists() ,in() ,ascending() ,descending() |
Syntax
function queryTags(options: QueryTagsOptions): TagsQueryBuilder
queryTags Parameters
NAME
TYPE
DESCRIPTION
Options specifying which fields to return.
Returns
Return Type:
Was this helpful?
This example uses the queryTags()
function to retrieve all tags.
1import { tags } from 'wix-blog-backend';23export async function queryTagsFunction() {4 try {5 const queryTagsResults = await tags.queryTags().find();6 const items = queryTagsResults.items;7 const firstItem = items[0];8 const pageSize = queryTagsResults.pageSize;9 const hasNext = queryTagsResults.hasNext();10 const hasPrev = queryTagsResults.hasPrev();11 const length = queryTagsResults.length;12 const query = queryTagsResults.query;13 return items;14 } catch (error) {15 console.error(error);16 }17}181920/* Returns:21 * [22 * {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 * "_createdDate": "2022-07-21T14:52:58.099Z",35 * "_id": "6a67d2ea-b758-49f1-a2bd-cce214246809",36 * "_updatedDate": "2022-07-21T14:52:58.099Z",37 * "label": "your tag",38 * "language": "en",39 * "postCount": 2,40 * "publishedPostCount": 2,41 * "slug": "your-tag",42 * "translationId": ""43 * }44 * {45 * "_createdDate": "2022-07-22T09:27:45.883Z",46 * "_id": "28230621-702d-4dab-af68-7a2a9b152fae",47 * "_updatedDate": "2022-07-22T09:27:45.883Z",48 * "label": "their tag",49 * "language": "en",50 * "postCount": 3,51 * "publishedPostCount": 3,52 * "slug": "their-tag",53 * "translationId": ""54 * },55 * ]56 */
This example uses the queryTags()
function to retrieve all tags.
1import { Permissions, webMethod } from 'wix-web-module';2import { tags } from 'wix-blog-backend';34export const queryTagsFunction = webMethod(Permissions.Anyone, async () => {5 try {6 const queryTagsResults = await tags.queryTags().find();7 const items = queryTagsResults.items;8 const firstItem = items[0];9 const pageSize = queryTagsResults.pageSize;10 const hasNext = queryTagsResults.hasNext();11 const hasPrev = queryTagsResults.hasPrev();12 const length = queryTagsResults.length;13 const query = queryTagsResults.query;14 return items;15 } catch (error) {16 console.error(error);17 }18});192021/* Returns:22 * [23 * {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 * "_createdDate": "2022-07-21T14:52:58.099Z",36 * "_id": "6a67d2ea-b758-49f1-a2bd-cce214246809",37 * "_updatedDate": "2022-07-21T14:52:58.099Z",38 * "label": "your tag",39 * "language": "en",40 * "postCount": 2,41 * "publishedPostCount": 2,42 * "slug": "your-tag",43 * "translationId": ""44 * }45 * {46 * "_createdDate": "2022-07-22T09:27:45.883Z",47 * "_id": "28230621-702d-4dab-af68-7a2a9b152fae",48 * "_updatedDate": "2022-07-22T09:27:45.883Z",49 * "label": "their tag",50 * "language": "en",51 * "postCount": 3,52 * "publishedPostCount": 3,53 * "slug": "their-tag",54 * "translationId": ""55 * },56 * ]57 */58
This example uses the queryTags()
function to retrieve all tags with a postCount
less than 3.
1import { Permissions, webMethod } from 'wix-web-module';2import { tags } from 'wix-blog-backend';34/* Sample options values:5 * {6 * fieldsets: [7 * 'URL'8 * ]9 * }10 */1112export const queryTagsFunction = webMethod(Permissions.Anyone, async () => {13 try {14 const queryTagsResults = await tags.queryTags()15 .lt('postCount', 3)16 .find();17 const items = queryTagsResults.items;18 const firstItem = items[0];19 const pageSize = queryTagsResults.pageSize;20 const hasNext = queryTagsResults.hasNext();21 const hasPrev = queryTagsResults.hasPrev();22 const length = queryTagsResults.length;23 const query = queryTagsResults.query;24 return items;25 } catch (error) {26 console.error(error);27 }28});2930/* Returns:31 * [32 * {33 * "_createdDate": "2022-07-19T10:30:03.607Z",34 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",35 * "_updatedDate": "2022-07-19T10:30:03.607Z",36 * "label": "my tag",37 * "language": "en",38 * "postCount": 1,39 * "publishedPostCount": 1,40 * "slug": "my-tag",41 * "translationId": "",42 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/tags/my-tag"43 * },44 * {45 * "_createdDate": "2022-07-21T14:52:58.099Z",46 * "_id": "6a67d2ea-b758-49f1-a2bd-cce214246809",47 * "_updatedDate": "2022-07-21T14:52:58.099Z",48 * "label": "your tag",49 * "language": "en",50 * "postCount": 2,51 * "publishedPostCount": 2,52 * "slug": "your-tag",53 * "translationId": "",54 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/tags/your-tag"55 * }56 * ]57 */