Discover in this tutorial how to support the WordPress REST API in a Custom Post Type (CPT) using code.
The nice thing about creating your own Custom Post Type is that you have full control over it.
For example?
If you want it to support the WordPress REST API just add the argument 'show_in_rest' => true,
in its array, as I show you in the example of creating a Custom Post Type using code.
Does your CPT have this support?
Then you can take advantage of both the block editor and the REST API and display the number of posts from another website.
Are you working with a Custom Post Type created by a third-party plugin and it does not allow you to modify it so easily?
That’s a quick fix with WordPress hooks. 😉
Snippet to support the REST API in a Custom Post Type
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this block you use the register_post_type_args
hook so that the Custom Post Type “Course” has support for the WordPress REST API.
Of course, you can change the slug to the one of the Custom Post Type you are interested in.
Conclusion
Now you know how to add support for the WordPress REST API in a Custom Post Type created by a third-party plugin.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉