Wordpress custom API development

时间:2017-11-13 06:13:51

标签: wordpress api

Below is the code I am using

add_action( 'rest_api_init', 'add_custom_users_api');

function add_custom_users_api(){
   register_rest_route( 'testing', '/users', array(
     'methods' => 'GET',
     'callback' => 'get_custom_users_data',
   ));
}

function get_custom_users_data($data){
    //get users by market
    $result = "Testing this";
    return $result;
}

Below is the response I am getting

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个

add_action( 'rest_api_init', 'add_custom_users_api');

function add_custom_users_api(){
    register_rest_route( 'testing', '/users', array(
        'methods' => 'GET',
        'callback' => 'get_custom_users_data',
    ));
}

function get_custom_users_data($data){
    //get users by market
    $result = "Testing this";
    return $result;
}

http://localhost/wordpress/wp-json/testing/users

enter image description here