wordpress - Wordpress REST API:获取原始数据库内容
问题描述
我想从我的事件日历中提取数据。所以我为我的事件内容类型添加了 REST API 支持。但我的 JSON 输出是 HTML。
我不能获取原始数据库数据吗?
我明白了:http ://astc.dk/wp-json/wp/v2/event/
我把它放在我的functions.php中
add_action( 'init', 'my_event_cpt', 25 );
function my_event_cpt() {
global $wp_post_types;
//be sure to set this to the name of your post type!
$post_type_name = 'event';
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';
}
}
解决方案
推荐阅读
- c# - 使用谓词作为字典中的键,尝试调用值时出错
- .net - ACCPAC 缺少方法异常
- java - 在 Java 10 中运行 Maven 原型“快速入门”?
- google-chrome - 从命令行运行 chrome 并推断页面何时完成加载
- google-oauth - 如何从 Google OAuth 获取性别和生日
- r - apply() 函数分别按顺序应用于矩阵的列和数值向量的元素
- asp.net - 在 TFS 上运行随机测试用例
- javascript - 如何使文本和图像淡入淡出作为幻灯片显示?
- javascript - 如何在字符串中传递字符串
- asp.net-mvc-4 - 如何调用某些控制器的方法并从查询字符串中传递参数