Get a term object using getEntityRecords

So getEntityRecords( ‘taxonomy’, ‘genre’ ) will make a request to the “list terms” endpoint at /wp/v2/genre (or /wp/v2/<rest_base> if your taxonomy uses a custom rest_base) in the REST API, and because the “list terms” endpoint for custom taxonomies by default use the same parameters used by /wp/v2/categories (the “list terms” endpoint for the built-in category … Read more

Register GET REST API route with multiple parameters

You don’t need to include query parameters in the endpoint. Just the path: register_rest_route( ‘myplugin/v1’, ‘/posts’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘my_rest_function’, ‘permission_callback’ => ‘__return_true’, ‘args’ => array( ‘number’ => array( ‘validate_callback’ => function( $param, $request, $key ) { return is_numeric( $param ); } ), ‘offset’ => array( ‘validate_callback’ => function( $param, $request, $key … Read more

Get user first name from custom endpoint

If you look at the documentation, first_name is not in the list of accepted values for the fields parameter, and if you enabled debugging, you’d see adding first_name to that parameter would actually cause a database error — Unknown column ‘wp_users.first_name’ in ‘field list’. And the same goes to the “firstname” and any other non-standard … Read more

Disable part of endpoints wordpress api

The routes in question have two or three default endpoints: /wp/v2/users — it has two endpoints, one GET and one POST, i.e. “List Users” (GET /wp/v2/users), and “Create a User” (POST /wp/v2/users). /wp/v2/users/<id> — it has three endpoints, one GET, one POST and one DELETE, i.e. “Retrieve a User” (GET /wp/v2/users/<id>), “Update a User” (POST … Read more

How to code auto-retry for API call

First you should save the data somewhere in your wordpress. I personally like to use custom tables. Then use a schedule (cron job) to check if there is new data. Then try to submit the data. If you sumitted the data successfully delete it or mark your local data as successfully submitted. Else retry it … Read more