Opened 9 years ago
Closed 9 years ago
#2828 closed defect (bug) (invalid)
Minor change on extending-the-rest-api
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Component: | Developer Hub | Keywords: | dev-feedback |
| Cc: |
Description
In https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
The given example works only replacing
$data['id']
by
$data['URL']['id']
/**
* Grab latest post title by an author!
*
* @param array $data Options for the function.
* @return string|null Post title for the latest,
* or null if none.
*/
function my_awesome_func( $data ) {
$posts = get_posts( array(
'author' => $data['URL']['id'],
) );
if ( empty( $posts ) ) {
return new WP_Error( 'awesome_no_author', 'Invalid author', array( 'status' => 404 ) );
}
return $posts[0]->post_title;
}
Note: See
TracTickets for help on using
tickets.