[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.
- The topic ‘[Plugin: JSON API] Empty comments array in post data (with solution)’ is closed to new replies.