I’m making use of WordPress REST API to fetch data required for running a mobile app.
I have added a new database table which stores user device registration number and post ids when the user saves a post from the mobile app.
When User requests the saved posts from mobile app, I want to list all the posts saved by user by fetching the data from database
I would like to know how I can add a query var to the existing API call and retrieve the saved posts by user
Currently, the below API query fetched latest 10 posts from blog
When I change the API by adding a regid var to the URL, it should fetch the posts that are saved by the specific user having regid 123456
How can I add this filter to API?
I’m getting the saved post ids from the table using the below query
$regid = $_REQUEST['regid'] ; $sql1 = "SELECT postid FROM ".$save_table." WHERE regid='".$regid."';"; $result1 = $wpdb->get_results($sql1);
Do I need to create a custom route for this? or I can filter on the existing one?
Read more here: Adding custom query vars to WordPress REST API