REST API: No route was found matching the URL and request method

It’s because of how you’ve defined the accepted methods: ‘methods’ => ‘\WP_REST_Server::CREATABLE ‘, You shouldn’t have quotes around it. WP_REST_Server::CREATABLE is a string that equals ‘POST’, but by putting quotes around it you’re literally setting the method as ‘\WP_REST_Server::CREATABLE’, which is not a valid HTTP method. You can see this in the response to the … Read more

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

WP REST API – Multisite – get posts from all sites

Here’s a REST API recipe for latest post per site on a multi-site, for relatively few sites: Use get_sites(), loop over sites and switch to each site, query latest post on each site, collect data, order data by utime, serve data Example REST Routes https://example.com/wp-json/wpse/v1/latest-post-per-site https://example.com/wp-json/wpse/v1/latest-post-per-site?number=10 https://example.com/wp-json/wpse/v1/latest-post-per-site?debug Example Plugin Here’s a demo plugin implementing the … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)