Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@onnimonni
Created November 20, 2017 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onnimonni/6b81eea074dad2c58902fad8174c7835 to your computer and use it in GitHub Desktop.
Save onnimonni/6b81eea074dad2c58902fad8174c7835 to your computer and use it in GitHub Desktop.
<?php
/**
* Add REST API support to an already registered post type.
*/
add_action( 'init', 'rata_post_type_rest_support', 25 );
function rata_post_type_rest_support() {
global $wp_post_types;
// Be sure to set this to the name of your post type!
$post_type_name = 'rata';
if( isset( $wp_post_types[ $post_type_name ] ) ) {
$wp_post_types[$post_type_name]->show_in_rest = true;
$wp_post_types[$post_type_name]->rest_base = $post_type_name;
$wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment