I am now creating an android app which planned to connect to a plugin(WP Job Manager) in my WordPress side. I installed REST-API plugin and successfully getting posts by:
mywp.org/wp-json/wp/v2/posts
However, results do not include custom posts which created by the plugin. I am new in rest-api and I am not sure what I should do.
Thankyou!
There are solutions, but the basic idea is that the custom post type must be registered with WP REST API.
You can refer to this link: http://v2.wp-api.org/extending/custom-content-types/
It should be something like this (put it in your functions.php, "cpt" = Custom Post Type, an arbitrary name):
function wpsd_add_cpt_args() {
global $wp_post_types;
$wp_post_types['cpt']->show_in_rest = true;
$wp_post_types['cpt']->rest_base = 'cpt';
$wp_post_types['cpt']->rest_controller_class = 'WP_REST_Posts_Controller';
}
add_action( 'init', 'wpsd_add_cpt_args', 30 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.