1.0.9 • Published 5 years ago

gatsby-wordpress-search v1.0.9

Weekly downloads
70
License
MIT
Repository
github
Last release
5 years ago

Gatsby Wordpress Search

Add search functionality (powered by Lunr.js) to your Gatsby site based on Wordpress data.

The plugin filters post title, post content and all ACF fields.

Requirements

Gatsby plugin: gatsby-source-wordpress

Instructions

  1. Upload the PHP file inside the plugin folder (see GitHub) as a plugin into Wordpress. Once this is done you should be able to see the json output at "/wp-json/wp/v2/searchResults".

  2. Include the route in your gatsby-config.js

{
      resolve: "gatsby-source-wordpress",
      options: {
        ...
        includedRoutes: ["**/searchResults"]
      }
    }
  1. Install the search component
yarn add gatsby-wordpress-search

or

npm i gatsby-wordpress-search
  1. Import the component and style it.
import React from "react";
import { StaticQuery, graphql, navigate } from "gatsby";
import styled from "styled-components";
import Search from "gatsby-wordpress-search";

<Wrapper>
  <StaticQuery
    query={graphql`
      {
        allWordpressWpSearchResults {
          edges {
            node {
              id
              post_title
              searchData
              pathname
            }
          }
        }
      }
    `}
    render={data => {
      return (
        <Search
          data={data}
          minCharacters={4}
          contentCharacters={300}
          maxResults={10}
          placeholder='Search'
          onSelect={object => navigate(o.pathname)}
        />
      );
    }}
  />
</Wrapper>;

const Wrapper = styled.div`
  .container {
  }

  .input {
  }

  .suggests {
  }

  .suggest {
  }

  .suggestTitle {
  }

  .suggestContent {
  }
`;
1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago