Is it possible to access pluggin’s data from WordPress database with some Rest API. I saw WP REST API but it doesn’t give access to pluggin’s data.
More specifically I use LearnDash pluggin and I want to access courses infos but they doesn’t provide any API to access it.
Thanks
Overall you need to search Google for things having to do with “WordPress rest api custom post type” and eventually you’ll be dealing with registering custom post types and endpoints in your theme’s functions.php
Here is the manual: https://developer.wordpress.org/rest-api/extending-the-rest-api
As an example, here is my situation: I’m using WordPress (4.7) and The Events Calendar (“TEC”) plugin. I’m querying the WP DB from an Android app using the REST API, however the only data that’s available to REST is basic WP post stuff. I need to expose the custom data in the TEC plugin to the REST API. In order to do that, I’ve included the following into my functions.php in my theme:
functions.php
With the above in my functions.php, now I can query just the custom post type and taxonomy with the REST API. Here’s a sample query:
http://www.mywebsite.com/wp-json/wp/v2/tribe_events?tribe_events_cat=64
However, I still don’t see any of the custom plugin data per-event. All I see are the basic standard WP fields.
So now I have to add more to my functions.php:
… and a bunch more endpoint definitions of which I’m excluding the code here.
Now when I run the same query from earlier, new data fields are present in the JSON: all of the endpoints I’ve added.
At this point I want to exclude a ton of things from the REST API output (all the miscellaneous WP stuff) and just return the event fields I’m interested in. To do that I just add a “&fields” parameter to my query, with fields seperated by comma. There’s also a per_page and order parameters too.
http://www.mywebsite.com/wp-json/wp/v2/tribe_events?tribe_events_cat=64&per_page=100&order=asc&fields=id,title.rendered,_EventVenueID.lat,_EventVenueID.lng,_EventVenueID.locid,_EventStartDate.startdate,tribe_events_cat
This returns JSON data with only the data I’m interested in.
The TEC plugin maker has stated they’ll be introducing official REST API support sometime soon. This means in the future I can probably eliminate all of this code in functions.php, and just utilize whatever interface the plugin maker comes up with… hopefully a nice sexy page inside the plugin settings.
Now that WP (4.7) has more or less a fully featured REST API, the ball is in the court of the plugin makers to build support for it. So this year you should see plugins be updated accordingly.
When you are creating the custom post type in WordPress just add one more parameter
show_in_rest
astrue
for the support the rest API for Custom post type.Please visit here.
Then you can use the custom endpoint by the URL like this:
https://example.com/wp-json/wp/v2/book