• Hello there,
    thanks for your great API.
    I have a small optimization.
    Introduced an aditional option “exclude_content” that, if true, prevents to send the content. This helps reducing the load if you just only need the page hierarchy.
    Hope it helps.

    public function get_page_index() {
        global $json_api;
        extract($json_api->query->get(array('exclude_content')));
        $pages = array();
        // Thanks to blinder for the fix!
        $numberposts = empty($json_api->query->count) ? -1 : $json_api->query->count;
        $wp_posts = get_posts(array(
          'post_type' => 'page',
          'post_parent' => 0,
          'order' => 'ASC',
          'orderby' => 'menu_order',
          'numberposts' => $numberposts
        ));
        foreach ($wp_posts as $wp_post) {
          $page = new JSON_API_Post($wp_post);
          if($exclude_content) {
            $page->set_value('content', '');
          }
          $pages[] = $page;
        }
        foreach ($pages as $page) {
          $json_api->introspector->attach_child_posts($page);
        }
        return array(
          'pages' => $pages
        );
      }
  • The topic ‘[Plugin: JSON API] optimization for get_page_index’ is closed to new replies.