Find out in this tutorial how to support the REST API of a WordPress taxonomy using code.
The nice thing about creating your own taxonomy, for example for a Custom Post Type, is that you have full control over it.
One of these advantages is that, if you want it to support the WordPress REST API, you just have to add the argument 'show_in_rest' => true,
in its array ($argsCategory); as I show you in the tutorial to create a Custom Post Type using code.
On the other hand, if you are working with a taxonomy created by a third party plugin you can’t modify it so easily.
What can you do then?
No problem. That’s what WordPress hooks are for. 😉
Snippet to support the REST API in a WordPress Taxonomy
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 hook register_taxonomy_args
so that the taxonomy “portfolio_category” (from the Custom Post Type “Portfolio”) has support for the WordPress REST API.
Of course, you can change the slug to the taxonomy of your choice.
Conclusion
Now you know how to add support for the WordPress REST API in a taxonomy.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂