Skip to content
WPGraphQL FacetWP integration plguin
PHP
Branch: master
Clone or download
hsimah
Latest commit 08554f8 Jul 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore release testing bugs (#15) Jul 3, 2019
LICENSE Feature/documentation (#13) Jun 27, 2019
README.md Merge remote-tracking branch 'origin/master' Jun 28, 2019
class-facetwp.php release testing bugs (#15) Jul 3, 2019
logo.png logo Jun 28, 2019
wp-graphql-facetwp.php Feature/documentation (#13) Jun 27, 2019

README.md

Logo

WPGraphQL-FacetWP: WPGraphQL provider for FacetWP

Quick Install

Download and install like any WordPress plugin.

Documentation

The WPGraphQL documentation can be found here. The FacetWP documentation can be found here.

  • Requires PHP 5.5+
  • Requires WordPress 4.7+
  • Requires WPGraphQL 0.3.2+
  • Requires FacetWP 3.3.9+

Overview

This plugin exposes configured facets through the graph schema. Once registered for a type, a query is available. The payload includes both facet choices and information and a connection to the post type data. This allows for standard GraphQL pagination of the returned data set.

Usage:

It is assumed that facets have been configured

To register a FacetWP query in the WPGraphQL schema for a WordPress post type (eg post) simply call the following function:

// Register facet for Posts
register_graphql_facet_type( 'post' );

This will create a WPGraphQL postFacet field on the RootQuery. The payload includes a collection of queried facets and a posts connection. The connection is a standard WPGraphQL connection supporting pagination and server side ordering. The connection payload only includes filtered posts.

A simple query might look like this:

query GetPosts($query: FacetQueryArgs, $after: String, $search: String, $orderBy: [PostObjectsConnectionOrderbyInput]) {
  postFacet(where: {status: PUBLISH, query: $query}) {
    facets {
      selected
      name
      label
      choices {
        value
        label
        count
      }
    }
    posts(first: 10, after: $after, where: {search: $search, orderby: $orderBy}) {
      pageInfo {
        hasNextPage
        endCursor
      }
      nodes {
        title
        excerpt
      }
    }
  }
}

Limitations

Currently the plugin only has been tested using Checkbox and Radio facet types. Support for additional types is in development.

You can’t perform that action at this time.