0

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

}

}
  • Double-check your quotation marks. The ones you posted here are smart quotes that won't work - you need straight ' quotes. Also double-check your CPT to see whether it is really named rooms plural, or if it might be room singular. They vary but best practice is to register them as singular, so that could also be affecting it. – WebElaine Jun 10 at 14:31
  • @WebElaine Wow you are Awesome havn't noticed that works like a charm thank you so much really appreciate – Osh Jun 10 at 14:39
  • @WebElaine one thing that is missing is those meta boxes info. do I need to do something else in order to access them? – Osh Jun 10 at 14:42
  • 1
    Yes, postmeta isn't available by default. See wordpress.stackexchange.com/questions/227506/… – WebElaine Jun 10 at 15:10
  • @WebElaine Thanks again saved the day totally appreciate the quick reply and Awesome Help :) – Osh Jun 10 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.