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
Returns
A PublicPlansQueryBuilder
object representing the refined query.
Return Type:
Was this helpful?
or
filter to a query1const newQuery = query1.or(query2);
or
filter, and run itThis 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".
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';23// ...45const date = new Date("2020-11-01");67wixPricingPlansBackend.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 found25 }26 })27 .catch((error) => {28 const queryError = error;29 });
or
filter, and run itThe 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.
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';23// ...45const now = new Date();6const date = new Date('2020-11-01');78const slugPlanQuery =9 wixPricingPlansBackend.queryPublicPlans()10 .startsWith("slug", "silver")11 .or(12 wixPricingPlansBackend.queryPublicPlans()13 .startsWith("slug", "gold")14 );1516const datePlanQuery =17 wixPricingPlansBackend.queryPublicPlans()18 .between("_createdDate", date, now);1920const typeAndDateQuery = slugPlanQuery.and(datePlanQuery);2122return 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 found39 }40 } )41 .catch((error) => {42 const queryError = error;43 } );4445/*46 * The results contain public47 * plans with slugs that start with48 * "gold" or "silver":49 *50 * gold The primary public plan is included51 * gold-vip52 * silver53 * silver-vip54 *55 * And no public plans created earlier than56 * November 11, 202057 */