Reputation: 11
I have developed a wordpress directory listings website and a corresponding android app. My plan is to fetch the categories, listings and other data from wordpress using Json, I tried using the Wordpress JSON REST API plugin but It seems to me that this only exposes the core WordPress functionality (ie. posts, pages, users, etc.) and I can't see how to get this to execute custom queries on non-default tables.. I am unable to fetch the Categories and Listings which I created using the WP Job Manager Plugin.
How can I go about this?
Upvotes: 1
Views: 485
Reputation: 151
Go to your wordpress setup plugins folder. Go to rest-api -> plugin.php.
Find this
function _add_extra_api_post_type_arguments() {
}
Add the following code before its closing tag and you'll have the api working on /v2/joblistings/
if ( isset( $wp_post_types['job_listing'] ) ) {
$wp_post_types['job_listing']->show_in_rest = true;
$wp_post_types['job_listing']->rest_base = 'joblistings';
$wp_post_types['job_listing']->rest_controller_class = 'WP_REST_Posts_Controller';
}
Add the following code before its closing tag and you'll have the api working on /v2/joblistingcategorys/
//Taxonomy for listings
if ( isset( $wp_taxonomies['job_listing_category'] ) ) {
$wp_taxonomies['job_listing_category']->show_in_rest = true;
$wp_taxonomies['job_listing_category']->rest_base = 'joblistingcategorys';
$wp_taxonomies['job_listing_category']->rest_controller_class = 'WP_REST_Terms_Controller';
}
Source is http://v2.wp-api.org/extending/custom-content-types/
Adding rest API support to existing content types.
Upvotes: 0