check the requesting url

That filter is definitely not the one you are looking for. That filter fires before returning the result of WP_REST_Request::from_url() which appears to be a factory method that is only used internally to handle embeds. A better option is to return a WP_Error instance on the rest_pre_dispatch filter. Some caveats: As mentioned by @milo, the … Read more

Search WP API using the post title

Unfortunately, it is not possible, but you can use slug instead. Like this: http://example.com/wp-json/wp/v2/posts?slug=table Reference document URL are: https://developer.wordpress.org/rest-api/reference/pages/#arguments

run silex or slim with wordpress

There’s little that you can do with the Silex server that can’t be done through WordPress but it takes a bit of effort to get WP to respond to AJAX calls. The first step is to make the call available through AJAX. This requires adding a line to your functions.php file similar to add_action(‘wp_ajax_my_ajax_call’, ‘onno_update_my_ajax_call’); … Read more

Query WP REST API v2 by multiple meta keys

Adding a custom endpoint is pretty straightforward. I also modified the url to look more like http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015 function wp_json_namespace_v2__init() { // create json-api endpoint add_action(‘rest_api_init’, function () { // http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015 register_rest_route(‘namespace/v2’, ‘/posts’, array ( ‘methods’ => ‘GET’, ‘callback’ => ‘wp_json_namespace_v2__posts’, ‘permission_callback’ => function (WP_REST_Request $request) { return true; } )); }); // handle the request … Read more

WP REST API Is it rather easy to rename the default wp-json uri part?

Please note that for current versions of WordPress, using the json_url_prefix filter no longer works. On WordPress 4.7 (and using the REST API from the core instead of a plugin), this is what I needed to change the API prefix. add_filter( ‘rest_url_prefix’, ‘my_theme_api_slug’); function my_theme_api_slug( $slug ) { return ‘api’; } If this doesn’t work … Read more

Building a custom REST API

TL;DR Yes, WordPress can certainly act as a backend for a mobile app. Yes, a page can act as a rest endpoint / interface. No, a theme template is not the right territory for the logic. Write your own plugin. Pointers I find it hard to believe that no one else has done this. I, … Read more

How to remove rest api link: in http headers?

The output is generated by the rest_output_link_header(). This function is used in two actions, wp_head and template_redirect in default-filters.php:@line234. You can remove the function from those hooks to remove the output you wanted to remove. Put the following codes in your theme’s functions.php to achieve the desired result. remove_action( ‘wp_head’, ‘rest_output_link_wp_head’, 10); remove_action( ‘template_redirect’, ‘rest_output_link_header’, … Read more

Can I use REST-API on plain permalink format?

Yes you can. Just add the rest_route query parameter. So https://wordpress.org/wp-json/ would become https://wordpress.org/?rest_route=/ Or https://wordpress.org/wp-json/wp/v2/ would become https://wordpress.org/?rest_route=/wp/v2 to give you a more complete example. So you’re wondering how to decide which one to use? Worry no more, there’s a function for that: get_rest_url() Another option is the fact that by default there is … Read more

Add media with WP-Rest-API v2

SO! This is fun. Keep in mind the WP-API is still very, very much a work-in-progress. Content-Disposition I found an issue reported on the WP-API issue queue about Content-Disposition. This is a required header for posting new media content and there are some very, very strict requirements when it comes to providing this in the … Read more

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