Add Custom Post Types to WP-API V2

You’ll notice if Version 2 of the WP-API (which is phenomenal by the way), you’ll need to add a couple things here or there to grab custom data.  Grab the function and below and throw that into your functions.php inside your theme.

function hijack_posts_types() {
    global $wp_post_types;
    
    // Add CPT slugs here, comma separated
    $arr = ['your','mom-is','funny','ha','ha'];
    
    foreach( $arr as $key ) {
      
  // If the post type doesn't exist, skip it
  if( !$wp_post_types[$key] )
    continue;
        
      $wp_post_types[$key]->show_in_rest = true;
  $wp_post_types[$key]->rest_base = $key;
    }
}
add_action( 'init', 'hijack_posts_types', 30 );