WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
Empty comments array in post data (with solution) (1 post)

  1. Marc
    Member
    Posted 1 year ago #

    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/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic