最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rest api - Get Custom Post types data from the API

programmeradmin1浏览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’;

}

}
发布评论

评论列表(0)

  1. 暂无评论