I am trying to create a REST APIs for my wordpress website which is used for facility listing using wordpress job manager plugin.
I have registered my custom post , taxonomies in \plugins\rest-api\plugin.php.
below API gives me all the listings with default response.
http://localhost/sports/wp-json/wp/v2/joblisting/
I wanted to add post meta in the JSON response using the below code.
function slug_register_phone_number() {
register_rest_field( 'job_listing',
'phone',
array(
'get_callback' => 'slug_get_phone_number',
'update_callback' => null,
'schema' => null,
)
);
}
function slug_get_phone_number($post, $field_name, $request) {
return get_post_meta($post->id, '_phone' );
}
}
Using above code i am able to add "phone" as a REST response but i am always getting phone = false in response. It is not showing the correct data from wp_postmeta table.
I have followed below mentioned links for reference.
http://v2.wp-api.org/extending/modifying/
Plug in details. 1. WP Job manager 2. rest-api
Any help will be really helpful.