rest api - 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 book

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

}

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742360155a4429232.html

相关推荐

  • rest api - 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 book

    2天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信