Hi @Daniele,
query data from an external API is so amazing, but will it be possible to use filters (Bricks native) on this query too ?
For example , I have a list of recipes in my JSON array, there is a key named “difficulty” with values like : easy, medium, difficult.
Can I filter my grid by difficulty ? If I select “easy” in a dropdown for example, only posts with this difficulty are displayed.
If this is possible, this is the absolute grail…
Hey Cedrik!
Unfortunately, this is not technically possible with the Bricks Filter, as they only work for the WordPress API. Such filtering options in external APIs are always dependent on what the API returns. Therefore, there will be no uniform solution to handle this via a Select field and Ajax.
You can read about what your REST API would need to provide for this here:
A non-Ajax sort and filter logic would be possible via Dynamic Routes, but only through a page reload and, as mentioned, if the REST API supports it.
Thanks for your answer, this totally make sense, I’m aware that it’s really difficult, I’ve been fighting with datatables and server-side processing…
The reload could be in AJAX in order to not reload all the page, and of course it needs to send the right data to the API in order to get the right answer… but maybe this is doable…
Maybe not in Bricks native filters, but Bricksforge filters
Each filter need to specify the name of the data sent to the API, for example :
I can send this to my API : https://myapi.com/?difficulty=easy
So, in my filter, the var name would be “difficulty” and it will the send the value selected in the dropdown.
Then get the results and reload the query loop in AJAX.
Something like that
Yes, but developing our own Bricksforge filter system would be really, really complex. It’s also an open box without an end, as users would always want more features for it. I’m cautious about whether to really bring that in. That’s not planned for now. But who knows what the future holds
Haha right, that’s ok
I imagine this method might create an unknown number of API requests, which might be against API usage terms with some providers.
how come this is not possible when you cache it in the db? Can Bricks builder filter the data from those tables? @Daniele
No. Bricks filters are designed to filter WordPress post objects only. Also, filtering should be done from the API itself to load only the data you need from the server.
Not necessarily you may have an api which contains all data but want to let users interact with the data from the api. They only want to see with filter A and not ABC.
The only way it can be done is by then using static pages and make 10 different apis in bricksforge and hard code the query param it should look for.
or if you make this External API loops Dynamic Query Param
or make them filterable, can’t you save the transient as wordpress post objects as cache instead to make it filterable?