Title: [Plugin: JSON API] Empty comments array in post data (with solution)
Last modified: August 20, 2016

---

# [Plugin: JSON API] Empty comments array in post data (with solution)

 *  [Marc](https://wordpress.org/support/users/jmaimarc/)
 * (@jmaimarc)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-json-api-empty-comments-array-in-post-data-with-solution/)
 * Requesting a post through the get_post function of the API returned the correct
   number of comments, but the actual comment array was empty.
 * The introspector public function get_comments is named the same as the wordpress
   core function, so you used SQL, but that didn’t work. Using get_comments() within
   get_comments() causes a recursive loop.
 * I used a different wordpress core function called get_approved_comments():
 *     ```
       public function get_comments($post_id) {
           global $wpdb;
           $comments = array();
           $wp_comments = get_approved_comments($post_id);
   
           foreach ($wp_comments as $wp_comment) {
             $comments[] = new JSON_API_Comment($wp_comment);
           }
           return $comments;
         }
       ```
   
 * I probably should have used an action hook, but I’m lazy.
 * [http://wordpress.org/extend/plugins/json-api/](http://wordpress.org/extend/plugins/json-api/)

The topic ‘[Plugin: JSON API] Empty comments array in post data (with solution)’
is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/json-api.svg)
 * [JSON API](https://wordpress.org/plugins/json-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/json-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/json-api/)
 * [Active Topics](https://wordpress.org/support/plugin/json-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/json-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/json-api/reviews/)

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [empty](https://wordpress.org/support/topic-tag/empty/)

 * 0 replies
 * 1 participant
 * Last reply from: [Marc](https://wordpress.org/support/users/jmaimarc/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-json-api-empty-comments-array-in-post-data-with-solution/)
 * Status: not resolved