Making WordPress.org

Opened 7 years ago

Closed 7 years ago

#2828 closed defect (bug) (invalid)

Minor change on extending-the-rest-api

Reported by: rafasashi's profile rafasashi 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;
}

Change History (1)

#1 @rafasashi
7 years ago

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.