[英]How do I get Custom Field Post Object data in WordPress REST API
[英]How do I get all records from custom table via wordpress rest api?
我在 wordpress 数据库中创建了一个名为custom_users
的自定义表。 我想通过我创建的 API 获取 custom_users 表中的所有记录。
函数.php
function get_wp_custom_users() {
global $wpdb;
$row = $wpdb->get_row("SELECT * FROM wp_custom_users");
return $row;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'wpcustomusers/v1', '/all/', array(
methods' => 'GET',
'callback' => 'get_wp_custom_users'
) );
} );
可以像这样访问端点: http://localhost/mywebsite/wp-json/wpcustomusers/v1/all
当我通过POSTMAN
访问端点时,我只看到one record
。
您知道如何改进我的 get_wp_custom_users() 方法来检索所有记录吗? 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.