How can I display faceted search results with WordPress?

The Swiftype Search WordPress plugin version 1.1.38 and greater provides the swiftype_render_facets theme function to enable you to easily add faceting to your search results page. To use it, follow these steps:

  • Update to the latest version of the Swiftype Search WordPress plugin.
  • Add a swiftype_search_params_filter function to your theme’s functions.php file that adds facet parameters to the search.
function swiftype_search_params_filter($params) {
    $params['facets[posts]'] = array('tags', 'category');
    return $params;
}

add_filter('swiftype_search_params', 'swiftype_search_params_filter', 8, 1);
  • Add a swiftype_render_facets() call to your search.php template. This is what actually renders the facets. You should place it where you want the facets to be rendered:

<?php swiftype_render_facets(); ?>

  • (Optional) Style the facets using CSS. You can target div.st-facets for your CSS rules to only affect the content inside the facets container.