[wp-meta] [Making WordPress.org] #2828: Minor change on extending-the-rest-api

Making WordPress.org noreply at wordpress.org
Wed May 17 11:31:57 UTC 2017


#2828: Minor change on extending-the-rest-api
---------------------------+--------------------------
 Reporter:  rafasashi      |      Owner:
     Type:  defect         |     Status:  new
 Priority:  normal         |  Milestone:
Component:  Developer Hub  |   Keywords:  dev-feedback
---------------------------+--------------------------
 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;
 }
 }}}

--
Ticket URL: <https://meta.trac.wordpress.org/ticket/2828>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list