kaioe
8/31/2018 - 8:28 AM

WP REST API - POST TYPE to JSON

WP REST API - POST TYPE to JSON

// http://kaioandrade.com/wp-json/wp/v2/portfolio

add_action( 'init', 'my_custom_post_type_rest_support', 25 );
 
function my_custom_post_type_rest_support() {
 
global $wp_post_types;
 
//be sure to set this to the name of your post type!
$post_type_name = 'planet';
 
if( isset( $wp_post_types[ $post_type_name ] ) ) {
 
$wp_post_types[$post_type_name]->show_in_rest = true;
// Optionally customize the rest_base or controller class
$wp_post_types[$post_type_name]->rest_base = $post_type_name;
$wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
 
}
 
}