Hey Thomas,
If you install the latest version of your plugin along with the WP REST API (which is already partially merged into core as a feature plugin), you are unable to access any data from the custom post types that this plugin registers.
With both plugins installed, visit yourdomain.com/wp-json/wp/v2/jobman_job
and you will see:
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}
register_post_type()
takes a new argument show_in_rest
which will expose some of the data.
So if I update the register_post_type()
call in jobman_page_taxonomy_setup()
from
register_post_type( 'jobman_job', array( 'exclude_from_search' => false, 'public' => true, 'show_ui' => false, 'singular_name' => __( 'Job', 'jobman' ), 'label' => __( 'Jobs', 'jobman' ) ) );
to
register_post_type( 'jobman_job', array( 'show_in_rest' => true, 'exclude_from_search' => false, 'public' => true, 'show_ui' => false, 'singular_name' => __( 'Job', 'jobman' ), 'label' => __( 'Jobs', 'jobman' ) ) );
I am then able to access some of the data – I installed the plugin on a live site with that line updated and as you can see here https://dakota-code.com/wp-json/wp/v2/jobman_job.
I emphasized “some” intentionally because the “one line of code” I suppose is a bit exaggerated if you want to go all the way with REST API support. In order to expose all of the fields in a job, you would need to use register_rest_field()
hooked to rest_api_init
see: https://v2.wp-api.org/extending/modifying/#examples for an example.
Is this plugin on Github somewhere? I’d be happy to send a PR with these updates so you can test it out.