This shortcode will help to retrieve Firestore store database through queries.
Remember to set the security rule for your viewers.
// Operation list
eq: '==',
ne: '!=',
gt: '>',
ge: '>=',
lt: '<',
le: '<=',
in: 'in',
ni: 'not-in',
ac: 'array-contains',
aca: 'array-contains-any',
// In order to sort the data, you can add order_by
. For example, this will order by title - descendant. You can also combine the orders: `order_by='firstName|asc,lastName|desc'`
Queries Firestore and Display as Table
// Query 'users' collection // email == dale@dalenguyen.me // age > 20 // display fields: email,firstName,lastName,age,gender // display as 'table' [firestore_search class='your-class-name' search_fields='email|age' search_operators='eq|gt' search_conditions='dale@dalenguyen.me|20' collection_name='users' display_fields='email,firstName,lastName,age,gender']
Queries Firestore and Display as Blocks
// Query 'users' collection
// email == dale@dalenguyen.me
// age > 20
// display fields: email,firstName,lastName,age,gender
// display as 'blocks'
[firestore_search class='your-class-name' search_fields='email|age' search_operators='eq|gt' search_conditions='dale@dalenguyen.me|20' collection_name='users' display_fields='email,firstName,lastName,age,gender' display_type='blocks']
// In order to sort the data, you can add order_by
. For example, this will order by title - descendant. You can also combine the orders: `order_by='firstName|asc,lastName|desc'`
[firestore_search class='your-class-name' search_fields='email|age' search_operators='eq|gt' search_conditions='dale@dalenguyen.me|20' collection_name='users' display_fields='email,firstName,lastName,age,gender' display_type='blocks' order_by="age|desc"]
// Query 'users' collection // email == dale@dalenguyen.me // food contains Ramen // display fields: email,firstName,lastName,age,gender,food // display as 'blocks' [firestore_search class='your-class-name' search_fields='email|food' search_operators='eq|ac' search_conditions='dale@dalenguyen.me|Ramen' collection_name='users' display_fields='email,firstName,lastName,age,gender,food' display_type='blocks' order_by="age|desc"]
Queries Firestore with Firebase UID
Users need to log in in order to retrieve their Firebase UID
// Query 'users' collection // userId == getFirebaseUid // age > 20 // display fields: email,firstName,lastName,age,gender // display as 'blocks' // getFirebaseUid will be replaced by Firebase UID after user logs in. [firestore_search class='your-class-name' search_fields='userId|age' search_operators='eq|gt' search_conditions='getFirebaseUid|20' collection_name='users' display_fields='email,firstName,lastName,age,gender' display_type='blocks']