function my_awesome_func( WP_REST_Request $request ){
$posts = get_posts( array(
'author' => (int) $request['id'],
) );
if ( empty( $posts ) )
return new WP_Error( 'no_author_posts', 'Записей не найдено', [ 'status' => 404 ] );
return $posts;
}
add_action( 'rest_api_init', function(){
register_rest_route( 'myplugin/v1', '/author-posts/(?P<id>\d+)', [
'methods' => 'GET',
'callback' => 'my_awesome_func',
] );
} );