Created
January 17, 2019 14:25
-
-
Save jonbrockett/99b6a5431a1898cecf51367bace47147 to your computer and use it in GitHub Desktop.
WP REST API on Existing Custom Post Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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