Why use JSON API to display recent posts?

why not WP_query?

http://www.htmlgoodies.com/beyond/javascript/provide-a-json-feed-from-your-wordpress-site-using-the-json-api-plugin.html, here if you look at the comment at the bottom the guy wants to display the recent posts using the JSON API plugin

but why bother, when you can do it with WP_query?

3 Answers
3

The JSON API is just a wrapper for WP_Query bundled with RESTful endpoints (add_rewrite_rules).

Its a way to speed up production by providing a framework which you otherwise would have to code yourself. In fact, if you build custom endpoints, you’ll end up using your own QP_Query loops!

The choice is really going to come down to the requirements of your project.

If you are displaying the posts in your site, use WordPress’ loop with your custom WP_Querys.

If you are planning on using it as a RESTful interface for other websites and apps, then the article you posted is spot on because the JSON API:

  • Provides stable endpoints (with versions) for other services to connect to
  • Is safe and time tested, as opposed to building your own API, as you can introduce vulnerabilites
  • Provides a way to find endpoints programatically (info)
  • Is headless, meaning it bypasses rendering any themes, making it faster

That being said, its not nescessarily the right solution. The best solution is always the one you can execute well.

Have a look at the WP REST API for more:

https://wordpress.org/plugins/json-rest-api/

Hope it helps!

Leave a Comment