Cannot access elements of json object

The result that is currently returned is raw text, which means data[0] accesses the first element (i.e. character) of the string, which is {. Obviously, you want to turn the returned data into a JSON object. To do this, jQuery.ajax() has a nifty property called dataType, which determines the way jQuery interprets the data returned … Read more

WordPress JSON API returns normal site page in html. How do I get it to give me JSON?

I’m likely doing it wrong, but when I form my requests for a WordPress installation at http://www.example.com/ like this: http://www.example.com/index.php?rest_route=/my/rest/route/here I end up getting proper responses back. I had a heck of a time figuring this out and ended up grokking a URL formatted like that in the HTML returned to me. I was expecting … Read more

How can I export post data in xml format?

I just want to make my own exporter Well, export_wp() will fetch the data (it builds the sql query, I think). So I’m not sure the benefit of using an api request to try and hand that data to export_wp(), unless you mean to generate the arguments for it via an endpoint, or some values … Read more

ping_status in JSON REST API

According to WordPress Codex, pings tells Whether the current post is open for pings. In human words, A ping is a “this site has new content” notification that invites search engine bots to visit your blog. For more info, have a look at this blog article.

How to use wp_send_json_error?

wp_send_json_error( ‘Error: Invalid data!’ ) Will echoes a JSON string: {“success”:false,”data”:”Error: Invalid data!”} The nice thing about wp_send_json_error() is, the parameter could also be a WP_Error object. As opposed to wp_send_json_success( ‘Everything okay.’ ) which echoes this JSON string: {“success”:true,”data”:”Everything okay.”} Both rely internally on wp_send_json() to echo the JSON data properly and die() afterwards. … Read more

Why use JSON API to display recent posts?

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 … Read more