Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 130709

Disable it during REST request

$
0
0

Replies: 0

This is actually a solution more than a question. Since I couldn’t find a repo to contribute to.

Problem
The plugin causes unwanted behaviours with wp rest api (built in in wp 4.7).

When the plugin is active, any attempt to search trough custom post types (eg /wp-json/wp/v2/posts?search=dante&post_type=book) fails returning any post type registered for rest.

Solution
In order to keep the (very useful, so congrats!) features of this plugin within the frontend, you need to disable it just for rest requests. The following snippet just do this.

/*
 *  Disable WP Extended Search during rest requests
 */
function ed_rest_disable_wpes() {
  if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    add_filter('wpes_enabled', '__return_false', 1, 1);
  }
}
add_action( 'rest_pre_serve_request', 'ed_rest_disable_wpes', 10, 0);

Viewing all articles
Browse latest Browse all 130709

Trending Articles