This snippet in functions.php does the trick for now, until I know what is happening with the API officially:
/**
* API Access to job titles and some other limited data.
* This will go into a plugin of its own at some point.
*/
add_action('rest_api_init', function () {
register_rest_route( 'wpjm_public/v1', '/title/(?P<id>\d+)',[
'methods' => 'GET',
'callback' => function(WP_REST_Request $request) {
// The ID of the job we want.
$post_id = $request->get_param('id');
// Get the job.
$post = get_post($post_id);
// Return the limited job details, if it is a job listing.
if ($post->post_type == 'job_listing') {
return [$post_id => ['post_title' => $post->post_title]];
}
// No post or the wrong type of post.
return new WP_Error('invalid_job', 'Invalid job', ['status' => 404]);
},
]);
});
I can get a job title using a URL like this:
http://example.com/wp-json/wpjm_public/v1/title/41820
The result is an array, and the job title is in any array, to allow for extending to return multiple jobs and multiple data items per job. It is limited by design as it is not taking into account any group security on the job listings, so only the minimum is exposed.
-
This reply was modified 8 years, 11 months ago by
Jason Judge.
-
This reply was modified 8 years, 11 months ago by
Jason Judge.
Plugin Contributor
jonryan
(@jonryan)
@judgej thanks for sharing that snippet. We don’t really have a timeline right now when the API will be done, however the intention is to allow WPJM to be completely API driven.
Thanks. I’ve since added get_permalink() and a few other bits of public data to my snippet. There is no security enforced on it, as none is needed in this case. Hopefully it will be useful to someone in the interim.
I will watch and wait with eager anticipation. It’s all good 🙂