beforeQuery( )


A hook that is triggered before a find() operation.

The beforeQuery() hook runs when:

  • The find function is called.
  • An action is performed on a dataset that retrieves items from the collection.
  • The collection is viewed in the CMS.
  • An item is exported from the collection.

The hook also runs when an action is performed on a dataset that retrieves items from the collection that the dataset is connected to.

Return a query or a Promise that resolves to a query from the beforeQuery() function. The returned query will be used as the query for the find operation.

Often, you will modify the query that is received in the query parameter by calling one or more WixDataQuery functions.

If the returned value is of the wrong type, the value is ignored.

A rejected Promise blocks the call to find() and also calls the onFailure() hook if it has been registered.

Because the beforeQuery() hook is called before find() is executed, it can affect the query that is used to retrieve items or block the find().

Method Declaration
Copy
Method Parameters
queryWixDataQueryRequired

The original query as specified by the caller.


contextHookContextRequired

Contextual information about the hook.

Returns
Return Type:Promise<WixDataQuery> | WixDataQuery
Was this helpful?
Yes
No