// register the endpoints needed
add_action( 'rest_api_init', function( ) {
/*
// post types to include
$_pts = array( 'posts', );
// loop the post types and create a rest endpoint for the ACF fields for them
foreach ( $_pts as $_pt ) {
// var_dump($_pt . '/acf');
// register the rest endpoint
register_rest_fieldregister_rest_route( 'kp-api/v1', $_pt . '/acf/(?P<id>\d+)', array(
'methods' => array( 'GET', ),
'get_callback' => function( $data ) {
return 'HERE';
},
'args' => array(
'id' => array( 'validate_callback' => function( $param, $request, $key ) {
return is_numeric( $param );
} ),
),
) );
}
*/
// register the rest endpoint
register_rest_route( 'kp-api/v1', '/TEST/(?P<id>\d+)', array(
'methods' => array( 'GET', ),
'get_callback' => function( $data ) {
return 'HERE';
},
'args' => array(
'id' => array( 'validate_callback' => function( $param, $request, $key ) {
return is_numeric( $param );
} ),
),
) );
} );
And, I cannot see the endpoint in the site's /wp-json/. I can however, see that at least the namespace itself is indeed created by browsing to it: /wp-json/kp-api/v1
However, there are no endpoints in it.
{
"namespace": "kp-api/v1",
"routes": {
"/kp-api/v1": {
"namespace": "kp-api/v1",
"methods": [
"GET"
],
"endpoints": [
{
"methods": [
"GET"
],
"args": {
"namespace": {
"required": false,
"default": "kp-api/v1"
},
"context": {
"required": false,
"default": "view"
}
}
}
],
"_links": {
"self": "https://example.com/wp-json/kp-api/v1"
}
}
},
"_links": {
"up": [
{
"href": "https://example.com/wp-json/"
}
]
}
}