As we saw in Create and Explore a Single WordPress Post Through Gutenberg and the REST API, there is a lot of data available to you. This data might not be configured exactly how you'd like it. For instance, maybe you want comments to load with the initial call to /posts/#ID
without having to make additional calls for Author and Comments.
In this lesson, you'll see how to extend a behavior by adding an action in the functions.php
file that lives in /wp-content/themes/twentytwenty
. We will use register_rest_field
to add Comments to the request for a post.