Skip to content

Instantly share code, notes, and snippets.

@jonbrockett
Created January 17, 2019 14:25
Show Gist options
  • Save jonbrockett/99b6a5431a1898cecf51367bace47147 to your computer and use it in GitHub Desktop.
Save jonbrockett/99b6a5431a1898cecf51367bace47147 to your computer and use it in GitHub Desktop.
WP REST API on Existing Custom Post Types
<?php
/**
* Add REST API to an existing custom post type
* Remember to add existing custom fields
*/
function add_cpts_to_api( $args, $post_type ) {
if ( 'post_name' === $post_type ) {
$args['show_in_rest'] = true;
}
return $args;
}
add_filter( 'register_post_type_args', 'add_cpts_to_api', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment