New WP Live Search Plugin Utilizes the WP REST API

Yesterday Nick Haskins, creator of Aesop Story Engine, released a new search plugin for WordPress. WP Live Search utilizes the new WP REST API, in combination with Backbone.js and Underscore.js, to deliver live search results as the user types in a search query. The result is instantaneous searching that doesn’t require pressing enter or refreshing the page.

WP Live Search is very much a working prototype but also provides a practical example of the WP REST API in action. I tested the plugin and the short clip below shows an example of searching through thousands of articles. Each result is displayed neatly with its corresponding featured image.

Haskins created the client-side search plugin to power the new search feature inside Lasso, his frontend editing plugin. He released the prototype on WordPress.org in order to get usability testing and feedback from a larger group of users. He’s also building the plugin as part of his day job, so it’s being developed with several different audiences in mind.

“Using the REST API was super important because we’re searching on ‘keyup’ and if that went through admin-ajax.php then shared hosts would likely melt down,” Haskins said. “So because it’s all client-side, it’s super lightweight and anything can run it.”

The feature is already built into Lasso but will not be released until Haskins has the chance to gather more feedback.

“I’m interested to see HOW users search, is the search too fast, is it too slow, etc.,” he said. “All of this will lead to a perfect search feature inside of Lasso.”

Haskins was previously hesitant to utilize the WP REST API before it has landed in WordPress core but the recent progress and momentum on the project inspired him to go for it.

“I was avoiding the REST API, but with a tentative merge this fall, and V2 going out, I think the time is ripe,” he said. “In using the REST API, I’ve learned that it’s very use case dependent and is really just another tool. There’s a time and place for it.”

WP Live Search is still under active development and may not be suitable for use in production just yet, but is functional and ready for testing. Here’s how to take it for a spin:

Install WP Live Search.

Install the official WP REST API plugin.

Add the shortcode [wp_live_search] to a page.

The shortcode accepts a few attributes, including type, placeholder, results, and target. More details are available on the plugin’s description page.

Haskins plans to add support for custom post types in the next major update to the plugin. If you’re interested in contributing, you can find WP Live Search on GitHub.