WP REST API — Adding Custom Fields to Custom Route
-
Hi all,
we know that adding a custom field to a native route of the WP REST API is pretty easy, and it looks something like this:
function user_favorites_count() { // Return the user's favorite count } add_action( 'rest_api_init', function () { register_rest_field( 'user', 'favorites_count', array( 'get_callback' => 'user_favorites_count', 'schema' => null )); });However, this does not seem to work for custom routes: for example, if I created a custom route named
customerand wanted to use it instead ofuseras theregister_rest_field, thefavorites_countfield does not get registered. So how do you add a custom field to a custom route?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘WP REST API — Adding Custom Fields to Custom Route’ is closed to new replies.