By Adriano Ferreira
New Custom URL Parameters in Custom SQL and Pagination
We are pleased to announce the 5.5.0 version of Rest Routes Pro. This time we’ve launched 2 very interesting features.
Custom SQL and URL Parameters
So far, with Custom SQL Query endpoint you were able to only use static SQL queries, so no chance to have something external to interact with the query. This is in the past now! You are able to insert custom URL parameters that you previously defined on your endpoint directly on your query.
For this, all you need is to wrap it with the placeholder, like %my_parameter%. So, your custom SQL query could look like this: “SELECT * FROM wp_posts WHERE ID = %post_id%”.
When you do this, internally, we will look for URL get parameter called post_id and replace the query placeholder with the get parameter value. Awesome, isn’t it?
We’ve added a section inside of “Limit and Offset” where you are able to define how we will find the current page number, we recommend to add a custom parameter (you can even use the helper button we’ve included for this) and then connect the Source field of the Page Number group with this custom parameter. Also, define how many items per page you would like to show.
After doing this, you will be able to use your endpoint pagination like this: http://example.dev/wp-json/namespace/my-route?page=2
We hope you truly enjoy this version and as always, please report any bugs you might find to email@example.com.
Happy New Year!!!