Title: [Plugin: JSON API] exclude doesn&#039;t work while include does
Last modified: August 19, 2016

---

# [Plugin: JSON API] exclude doesn't work while include does

 *  [archon810](https://wordpress.org/support/users/archon810/)
 * (@archon810)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-json-api-exclude-doesnt-work-while-include-does/)
 * The exclude option doesn’t seem to work, while include does.
 * For example, /api/get_recent_posts/?page=1&count=1&dev=1&include=date works fine
   and returns just the date for each object, but /api/get_recent_posts/?page=1&
   count=1&dev=1&exclude=date still returns date along with the rest of the fields.
 * The problem lies in this code:
 *     ```
       function setup() {
           global $json_api;
           $this->include_values = array();
           if ($json_api->query->include) {
             $this->include_values = explode(',', $json_api->query->include);
           }
           if ($json_api->query->exclude) {
             $exclude = explode(',', $json_api->query->exclude);
             $this->include_values = array_diff($this->include_values, $exclude);
           }
         }
       ```
   
 * For includes, it works fine, but for excludes, it tries to subtract from an empty
   array, getting nada, and then this code:
 *     ```
       function is_value_included($key) {
           if (empty($this->include_values)) {
             return true;
           } else {
             return in_array($key, $this->include_values);
           }
         }
       ```
   
 * forces everything to be included.
 * I’ve thought about the possible solutions and the only ones that come to mind
   are: either maintain a comprehensive list of includes and then remove whatever
   is in excludes (not so elegant), or maintain a separate exclude option and have
   the is_value_included() function check this list in addition to the inclusion
   list.
 * [http://wordpress.org/extend/plugins/json-api/](http://wordpress.org/extend/plugins/json-api/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [ikesyo](https://wordpress.org/support/users/ikesyo/)
 * (@ikesyo)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-json-api-exclude-doesnt-work-while-include-does/#post-1697087)
 * Hi,
 * I worked around the problem.
 * response.php:
 *     ```
       function setup() {
           global $json_api;
           $this->include_values = array();
           $this->exclude_values = array();
           if ($json_api->query->include) {
             $this->include_values = explode(',', $json_api->query->include);
           }
           if ($json_api->query->exclude) {
             $this->exclude_values = explode(',', $json_api->query->exclude);
             $this->include_values = array_diff($this->include_values, $this->exclude_values);
           }
         }
       ```
   
 *     ```
       function is_value_included($key) {
           if (empty($this->include_values) && empty($this->exclude_values)) {
             return true;
           } else {
             if (empty($this->exclude_values)) {
               return in_array($key, $this->include_values);
             } else {
               return !in_array($key, $this->exclude_values);
             }
           }
         }
       ```
   
 * It seems to work properly.
 *  [ikesyo](https://wordpress.org/support/users/ikesyo/)
 * (@ikesyo)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-json-api-exclude-doesnt-work-while-include-does/#post-1697088)
 * Sorry, 2nd part of the cord is berrow.
 *     ```
       function is_value_included($key) {
           if (empty($this->include_values) && empty($this->exclude_values)) {
             return true;
           } else {
             if (!empty($this->include_values)) {
               return in_array($key, $this->include_values);
             } else {
               return !in_array($key, $this->exclude_values);
             }
           }
         }
       ```
   
 *  Plugin Author [dphiffer](https://wordpress.org/support/users/dphiffer/)
 * (@dphiffer)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/plugin-json-api-exclude-doesnt-work-while-include-does/#post-1697097)
 * Thanks guys, this will be fixed in the forthcoming release!
 *  Thread Starter [archon810](https://wordpress.org/support/users/archon810/)
 * (@archon810)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/plugin-json-api-exclude-doesnt-work-while-include-does/#post-1697101)
 * Thanks for fixing in the latest release – I just upgraded and will be checking
   back to see if the exclude option works soon.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: JSON API] exclude doesn't work while include does’ 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/)

 * 4 replies
 * 3 participants
 * Last reply from: [archon810](https://wordpress.org/support/users/archon810/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/plugin-json-api-exclude-doesnt-work-while-include-does/#post-1697101)
 * Status: not resolved