WordPress 4.7 REST API endpoints

According to ticket #38373 the following endpoints will be supported in version 4.7. Let me quote Rachel Baker: REST API endpoints for your WordPress content. These endpoints provide machine-readable external access to your WordPress site with a clear, standards-driven interface, allowing new and innovative apps for interacting with your site. These endpoints support all of … Read more

WP REST API core major changes

As of WordPress 4.7 now we have the following filter to hook to: $args = apply_filters( “rest_{$this->post_type}_query”, $args, $request ); So if you would like to perform a request like: http://yoursite.com/wp-json/wp/v2/posts?meta_key=your_key&meta_value=your_value&per_page=10 OR http://yoursite.com/wp-json/wp/v2/posts?meta_query[0][key]=your_key&meta_query[0][value]=your_value&per_page=10 you can do it through the following piece of code (within your functions.php): /** * This function will allow custom parameters within … Read more

How to Authenticate WP REST API with JWT Authentication using Fetch API

‘Authenticate’: ‘Basic {what do I put here?}’ // Do I need “Basic”? No, it’s not Basic. It’s Bearer. And the header is Authorization. So first, obtain a token from /wp-json/jwt-auth/v1/token: fetch( ‘http://example.com/wp-json/jwt-auth/v1/token’, { method: ‘POST’, body: JSON.stringify( { // Username of a user on the WordPress website in which the REST API request // is … Read more

Using the REST API (v2) javascript client on a private namespaced route

To modify the rest url prefix you can filter rest_url_prefix. But that just changes the /wp-json/ prefix that every namespace uses. Trying to modify wp/v2 means modifying the plugin and that namespace is hard-coded in several places like; WP_REST_Post_Statuses_Controller. To add your own custom endpoints, register_rest_route is in core to do just that. <?php add_action( … Read more

Adding WordPress API Endpoint With Multiple Parameters

I have the same problem, i search on google finally with the help of the above answer i found out the solution. this may help others. $this->base = home register_rest_route( $namespace, “https://wordpress.stackexchange.com/” . $this->base . “https://wordpress.stackexchange.com/” . ‘products’ . “https://wordpress.stackexchange.com/”, array( array( ‘methods’ => WP_REST_Server::READABLE, ‘callback’ => array( $this, ‘rest_api_popular_products’), ), ) ); register_rest_route( $namespace, … Read more