{"action":"created","issue":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/2625","repository_url":"https://api.github.com/repos/WP-API/WP-API","labels_url":"https://api.github.com/repos/WP-API/WP-API/issues/2625/labels{/name}","comments_url":"https://api.github.com/repos/WP-API/WP-API/issues/2625/comments","events_url":"https://api.github.com/repos/WP-API/WP-API/issues/2625/events","html_url":"https://github.com/WP-API/WP-API/issues/2625","id":168031118,"number":2625,"title":"Custom endroute with default schema, best way to go?","user":{"login":"MarioFromBelgium","id":8712620,"avatar_url":"https://avatars.githubusercontent.com/u/8712620?v=3","gravatar_id":"","url":"https://api.github.com/users/MarioFromBelgium","html_url":"https://github.com/MarioFromBelgium","followers_url":"https://api.github.com/users/MarioFromBelgium/followers","following_url":"https://api.github.com/users/MarioFromBelgium/following{/other_user}","gists_url":"https://api.github.com/users/MarioFromBelgium/gists{/gist_id}","starred_url":"https://api.github.com/users/MarioFromBelgium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarioFromBelgium/subscriptions","organizations_url":"https://api.github.com/users/MarioFromBelgium/orgs","repos_url":"https://api.github.com/users/MarioFromBelgium/repos","events_url":"https://api.github.com/users/MarioFromBelgium/events{/privacy}","received_events_url":"https://api.github.com/users/MarioFromBelgium/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-28T07:29:34Z","updated_at":"2016-07-30T08:14:06Z","closed_at":"2016-07-29T17:17:23Z","body":"Hi,\r\n\r\nI have a working custom end-route that accepts longitude and latitude data. The end-route's callback function searches for the posts nearest to the given location.\r\nToday the callback function returns a custom array containing different fields of these nearest posts. \r\n(All this is working perfectly)\r\nHowever I want my callback function to return the default schema that a default /wp/v2/posts end-route would return.\r\n\r\nBefore going into details I would like to know what, in general, would be the best way to go. To me it seems there are two ways to do this :\r\n\r\nIn my custom class that extends WP_REST_Posts_Controller \r\nOption 1°  I could paste the get_Items function and alter this function.\r\nOption 2°  I could alter my existing function so that it returns the default schema for posts\r\nMaybe there are more/better ways?\r\n\r\nI have tried both ways without success so I'm doing something wrong. As soon as somebody can tell me what the best option would be I would like to go into more detail.\r\n\r\nRegards,\r\nMario"},"comment":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/comments/236352495","html_url":"https://github.com/WP-API/WP-API/issues/2625#issuecomment-236352495","issue_url":"https://api.github.com/repos/WP-API/WP-API/issues/2625","id":236352495,"user":{"login":"MarioFromBelgium","id":8712620,"avatar_url":"https://avatars.githubusercontent.com/u/8712620?v=3","gravatar_id":"","url":"https://api.github.com/users/MarioFromBelgium","html_url":"https://github.com/MarioFromBelgium","followers_url":"https://api.github.com/users/MarioFromBelgium/followers","following_url":"https://api.github.com/users/MarioFromBelgium/following{/other_user}","gists_url":"https://api.github.com/users/MarioFromBelgium/gists{/gist_id}","starred_url":"https://api.github.com/users/MarioFromBelgium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarioFromBelgium/subscriptions","organizations_url":"https://api.github.com/users/MarioFromBelgium/orgs","repos_url":"https://api.github.com/users/MarioFromBelgium/repos","events_url":"https://api.github.com/users/MarioFromBelgium/events{/privacy}","received_events_url":"https://api.github.com/users/MarioFromBelgium/received_events","type":"User","site_admin":false},"created_at":"2016-07-30T08:14:06Z","updated_at":"2016-07-30T08:14:06Z","body":"Thx @BE-Webdesign ,\r\n\r\nI created a custom endroute like this : \r\nhttp://mydomain/wp-json/my-namespace/posts/lat=(?P<lat>[+-]?[\\\\d.]+)&lng=(?P<long>[+-]?[\\\\d.]+)&dst=(?P<distance>\\\\d+)\r\n\r\nMy current custom callbackfunction returns an array with the 10 nearest posts each containing an array with a few fields(title, excerpt etc..). Every post (they are not custom posts) has two custom fields lat/long.\r\n\r\nI will check prepare_item_for_response() and parent::get_item_schema().\r\n\r\nAlthough I would have thought the easiest and most logic way to do this was just call get_items right after setting the posts_in or include item in the request object?"}}
{"actor":{"display_login":"MarioFromBelgium"}}