Created
August 28, 2018 00:57
-
-
Save furenku/1bee67b573a72acbd3a61e14c86c6728 to your computer and use it in GitHub Desktop.
Insert Custom Post Types in REST API
This file contains hidden or 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 | |
| // 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