Coder Social home page Coder Social logo

wds-react-post-search's Introduction

WDS React Post Search

Power up the basic WordPress search with React. This plugin taps into the WP REST API and uses React to power a real-time search of posts.

WebDevStudios. WordPress for big brands.

How does it work?

This taps into the search-form class (or whatever class you filter to above) to display results when you begin typing in any search input matching that same class.

Options

Search more than just posts

By default, the plugin will search only posts. However, you can use a filter like this to provide access to multiple post types. Your posts types must have show_in_rest set to true when registering your post type.

function _s_filter_post_types_to_query() {
    return array(
        'post_type_slug',
        'page',
    );
}
add_filter( 'wds_react_post_search_filter_post_types', '_s_filter_post_types_to_query' );

Filter the search messages

By default, we're displaying text like Loading... when results are loading, No results found. when no results are found, and Please enter at least 3 characters. when attempting to search with too few characters. These can all be filtered from your theme!

function _s_filter_search_loading_text() {
    return esc_html( 'Give us a second – results are loading!', '_s' );
}
add_filter( 'wds_react_post_search_loading_text', '_s_filter_search_loading_text' );
function _s_filter_search_no_results_text() {
    return esc_html( 'There are no results here, buddy.', '_s' );
}
add_filter( 'wds_react_post_search_no_results_text', '_s_filter_search_no_results_text' );
function _s_filter_search_length_error_text() {
    return esc_html( 'You need more characters!', '_s' );
}
add_filter( 'wds_react_post_search_length_error_text', '_s_filter_search_length_error_text' );

Change the minimum character limit?

There's a filter for that too. If you want the search to start working as soon as you start typing, just set your value to 0 or 1. Otherwise, you can set this to whatever number you wish. Remember, this is character count and not letter count – spaces count!

function _s_filter_search_minimum_character_count() {
	return 0;
}
add_filter( 'wds_react_post_search_minimum_character_count', '_s_filter_search_minimum_character_count' );

Does your search form use a different class? No problem!

By default, the plugin will target search-form as is set in the localize_script call:

'search_form_class' => apply_filters( 'wds_react_post_search_search_form_class', esc_attr( 'search-form' ) )

However, this can also be filtered if your search form uses another class or you want to target a specific instance of a form on a page:

function _s_filter_search_search_form_class() {
	return esc_attr( 'some-other-class' );
}
add_filter( 'wds_react_post_search_search_form_class', '_s_filter_search_search_form_class' );

Local Development

Clone this repo

git clone [email protected]:WebDevStudios/WDS-React-Post-Search.git

Change directories

cd WDS-React-Post-Search

Install NPM modules

npm i

Kick off development server

npm run start

Build production ready assets

npm run build

Note

WordPress wont recognize any plugins whose folder is Camel-Case. You'll need to rename this folder to: wds-react-post-search

wds-react-post-search's People

Contributors

coreymcollins avatar davebonds avatar gregrickaby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

isabella232 dexit

wds-react-post-search's Issues

HTML entities are not decoded for use on frontend

In 605d490 the search_posts method is getting the proper post title and then later returning it through rest_ensure_response which appears to encode “some” characters as HTML entities. So we need a way to decode those entities in JS for use on frontend.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.