Title: JSON API Custom Post Types
Last modified: August 21, 2016

---

# JSON API Custom Post Types

 *  Resolved [thewirelessguy](https://wordpress.org/support/users/thewirelessguy/)
 * (@thewirelessguy)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/json-api-custom-post-types/)
 * I’m trying to get custom post types to work with the Jetpack JSON module. I’ve
   added the following to my functions.php to whitelist my custom post type ‘portfolio’:
 * add_filter( ‘rest_api_allowed_post_types’, array($this, ‘allow_my_post_types’));
 * function allow_my_post_types($allowed_post_types) {
    if (! defined(‘REST_API_REQUEST’)
   || ! REST_API_REQUEST) return $allowed_post_types; $allowed_post_types[] = ‘portfolio’;
   return $allowed_post_types; }
 * Unfortunately I’m still getting this error:
    {“error”: “unknown_post_type”,”message”:“
   Unknown post type”} I’m using [https://public-api.wordpress.com/rest/v1/sites/www.thewirelessguy.co.uk/posts/?type=portfolio](https://public-api.wordpress.com/rest/v1/sites/www.thewirelessguy.co.uk/posts/?type=portfolio)
   to call the JSON.
 * Any ideas?
 * [http://wordpress.org/extend/plugins/jetpack/](http://wordpress.org/extend/plugins/jetpack/)

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

 *  [reimerix](https://wordpress.org/support/users/reimerix/)
 * (@reimerix)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/json-api-custom-post-types/#post-3700666)
 * Okay, i actually don’t really have a clue what I did here, but this fixed it 
   for me:
 *     ```
       function allow_my_post_types($allowed_post_types) {
       $allowed_post_types[] = 'portfolio';
       return $allowed_post_types;
       }
   
       add_filter( 'rest_api_allowed_post_types', 'allow_my_post_types');
       ```
   
 * Thanks for providing your example in the first place 🙂
 *  Thread Starter [thewirelessguy](https://wordpress.org/support/users/thewirelessguy/)
 * (@thewirelessguy)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/json-api-custom-post-types/#post-3700671)
 * A huge thanks to you. The problem seems to have been with the array($this,”).
   I tried adding back in the other parts of the function with just the changes 
   you made to add_filter and it still worked. The function I wrote was based on
   the bbpress example they included in the plugin.

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

The topic ‘JSON API Custom Post Types’ is closed to new replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

## Tags

 * [json](https://wordpress.org/support/topic-tag/json/)

 * 2 replies
 * 2 participants
 * Last reply from: [thewirelessguy](https://wordpress.org/support/users/thewirelessguy/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/json-api-custom-post-types/#post-3700671)
 * Status: resolved