and( )


Adds an and condition to the query.

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

Note that when chaining multiple PublicPlansQueryBuilder functions to a query an and condition is assumed. In such cases, you do not need to add a call to the and() function. For example, this query returns results where the plan was created during a certain date range and the plan's slug starts with "gold" (such as gold, gold-vip, gold-trial).

Copy
wixPricingPlansBackend .queryPublicPlans() .between("_createdDate", specificDate, now) .startsWith("slug", "gold");

The and() function is needed when performing compound queries. For example, the final query, typeAndDateQuery, in this set of queries returns results where a plan is created after a certain date, and the plan is either a "gold" or a "silver" membership plan, as defined in the plan's slug.

Copy
const slugPlanQuery = wixPricingPlansBackend.queryPublicPlans() .startsWith("slug", "silver") .or( wixPricingPlansBackend.plans.queryPublicPlans() .startsWith("slug", "gold") ); const datePlanQuery = wixPricingPlansBackend.queryPublicPlans() .between("_createdDate", date, now); ); const typeAndDateQuery = slugPlanQuery.and(datePlanQuery);

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

Method Declaration
Copy
function and(query: PublicPlansQueryBuilder): PublicPlansQueryBuilder;
Method Parameters

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

Returns
JavaScript
const newQuery = query1.and(query2);
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?