Search.../

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.

PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),hasSome()
labeleq(),ne(),startsWith(),hasSome(),exists(),in(),ascending(),descending()
slugeq(),ne(),startsWith(),hasSome(),exists(),in(),ascending(),descending()
publicationCounteq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
postCounteq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
translationIdeq(),ne(),exists(),in()
languageeq(),ne(),exists(),in(),ascending(),descending()

Syntax

function queryTags(options: QueryTagsOptions): TagsQueryBuilder

queryTags Parameters

NAME
TYPE
DESCRIPTION
options
Optional
QueryTagsOptions

Options specifying which fields to return.

Returns

Return Type:

Was this helpful?

Retrieves a list of all tags

This example uses the queryTags() function to retrieve all tags.

Copy Code
1import { tags } from 'wix-blog-backend';
2
3export 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}
18
19
20/* 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 */
Query for tags with filters.

This example uses the queryTags() function to retrieve all tags with a postCount less than 3.

Copy Code
1import { tags } from wix-blog-backend;
2
3/* Sample options values:
4 * {
5 * fieldsets: [
6 * 'URL'
7 * ]
8 * }
9 */
10
11export async function queryTagsFunction() {
12 try {
13 const queryTagsResults = await tags.queryTags()
14 .lt('postCount', 3)
15 .find();
16 const items = queryTagsResults.items;
17 const firstItem = items[0];
18 const pageSize = queryTagsResults.pageSize;
19 const hasNext = queryTagsResults.hasNext();
20 const hasPrev = queryTagsResults.hasPrev();
21 const length = queryTagsResults.length;
22 const query = queryTagsResults.query;
23 return items;
24 } catch (error) {
25 console.error(error);
26 }
27}
28
29
30/* 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 */