Get Custom Post types data from the API


I’m new to the wp-api. I’m trying to fetch some data that is being generated by a plugin.
in my case is a booking plugin named Hotelier. I’v understood that from version 2 of the api you need to specify the show_in_rest = true.

I’v followed this Article, but with no luck after trying to add the code to functions.php and even create a simple plugin.

  1. Do I need to add the code from the article in function.php or register a new plugin
  2. the Autor of the plugin mentioned the data is stored in meta boxes does it make any difference?

any tips here please, cheers to all

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 = ‘rooms’;

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’;


, Osh 7 months 0 Answers 100 views 0

Leave an answer