Hiding API routes list

You can use the filter hook ‘rest_index’ : add_filter(‘rest_index’, function ($response) { $data = $response->get_data(); $data[‘namespaces’] = []; $data[‘routes’] = []; return $data; }, 9999, 1); It is possible to remove your route from $data[‘namespaces’] and $data[‘routes’]

wordpress wp-json prefix issue

You need to set the permalink structure of your website. Goto Settings > Permalink. Remove index.php from the Custom Structure. Click on Save Changes. It re-generate your permalink structure. And you’ll be able to access the posts with http://example.com/index.php/wp-json/wp/v2/posts Updated: .htaccess code like below: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /dev.fresh/ RewriteRule ^index\.php$ … Read more

How to get all posts from parent and children categories?

I had the same use case than you — calling WP-API from React — and ran into the same issue. Unfortunately WP-API does not support filtering by parent categories. In order to support it, you could extend the API’s functionality, adding a new filter that will run a tax_query behind the scenes, similar to Faye’s … 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

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

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