Skip to content

Instantly share code, notes, and snippets.

@furenku
Created August 28, 2018 00:57
Show Gist options
  • Select an option

  • Save furenku/1bee67b573a72acbd3a61e14c86c6728 to your computer and use it in GitHub Desktop.

Select an option

Save furenku/1bee67b573a72acbd3a61e14c86c6728 to your computer and use it in GitHub Desktop.
Insert Custom Post Types in REST API
<?php
// Plugin Name: Insert Custom Post Types in REST API
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 = 'offers';
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';
}
//be sure to set this to the name of your post type!
$post_type_name = 'branch';
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