Search.../

or( )

Adds an or condition to the query.

Description

The or() function adds an inclusive or condition to a PublicPlansQueryBuilder. A query with an or returns all the items that match the query as defined up to the or function, the items that match the query passed to the or function, and the items that match both.

The 'or()' function is designed to work with 2 or more queries. If you use it on its own, it will return all the items in a collection.

Syntax

function or(query: PublicPlansQueryBuilder): PublicPlansQueryBuilder

or Parameters

NAME
TYPE
DESCRIPTION
query

A query to add to the initial query as an or condition.

Returns

A PublicPlansQueryBuilder object representing the refined query.

Was this helpful?

Add an or filter to a query

Copy Code
1const newQuery = query1.or(query2);
Create a query, add an or filter, and run it

This query shows public VIP plans that were either created after a certain date. It is assumed that the slug of all VIP public plans ends with the characters "vip".

Copy Code
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';
2
3// ...
4
5const date = new Date("2020-11-01");
6
7wixPricingPlansBackend.queryPublicPlans()
8 .gt("_createdDate", date)
9 .or(wixPricingPlansBackend.queryPublicPlans().endsWith("slug", "vip"))
10 .find()
11 .then((publicPlans) => {
12 if (publicPlans.items.length > 0) {
13 const items = publicPlans.items;
14 const firstItem = items[0];
15 const totalCount = publicPlans.totalCount;
16 const pageSize = publicPlans.pageSize;
17 const currentPage = publicPlans.currentPage;
18 const totalPages = publicPlans.totalPages;
19 const hasNext = publicPlans.hasNext();
20 const hasPrev = publicPlans.hasPrev();
21 const length = publicPlans.length;
22 const query = publicPlans.query;
23 } else {
24 // handle case where no matching items found
25 }
26 })
27 .catch((error) => {
28 const queryError = error;
29 });
Create a compound query, add an or filter, and run it

The final query, typeAndDateQuery, in this set of queries returns results where a plan is created after a certain date (November 11, 2020), and the plan is either a "gold" or a "silver" membership plan, as defined in the plan's slug. Also, when combined with the eq filter, the query also includes the primary plan.

Copy Code
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';
2
3// ...
4
5const now = new Date();
6const date = new Date('2020-11-01');
7
8const slugPlanQuery =
9 wixPricingPlansBackend.queryPublicPlans()
10 .startsWith("slug", "silver")
11 .or(
12 wixPricingPlansBackend.queryPublicPlans()
13 .startsWith("slug", "gold")
14 );
15
16const datePlanQuery =
17 wixPricingPlansBackend.queryPublicPlans()
18 .between("_createdDate", date, now);
19
20const typeAndDateQuery = slugPlanQuery.and(datePlanQuery);
21
22return wixPricingPlansBackend.queryPublicPlans()
23 .eq("primary", true).or(typeAndDateQuery)
24 .find()
25 .then((publicPlans) => {
26 if(publicPlans.items.length > 0) {
27 const items = publicPlans.items;
28 const firstItem = items[0];
29 const totalCount = publicPlans.totalCount;
30 const pageSize = publicPlans.pageSize;
31 const currentPage = publicPlans.currentPage;
32 const totalPages = publicPlans.totalPages;
33 const hasNext = publicPlans.hasNext();
34 const hasPrev = publicPlans.hasPrev();
35 const length = publicPlans.length;
36 const query = publicPlans.query;
37 } else {
38 // handle case where no matching public plans found
39 }
40 } )
41 .catch((error) => {
42 const queryError = error;
43 } );
44
45/*
46 * The results contain public
47 * plans with slugs that start with
48 * "gold" or "silver":
49 *
50 * gold The primary public plan is included
51 * gold-vip
52 * silver
53 * silver-vip
54 *
55 * And no public plans created earlier than
56 * November 11, 2020
57 */