Skip to content

Instantly share code, notes, and snippets.

@ethanclevenger91
Last active September 27, 2020 08:32
Show Gist options
  • Save ethanclevenger91/b538d84b75493a82b6cfe5f9dd9b763a to your computer and use it in GitHub Desktop.
Save ethanclevenger91/b538d84b75493a82b6cfe5f9dd9b763a to your computer and use it in GitHub Desktop.
Add FacetWP facets with code-based ones, with preference for code-based definitions over db ones with same name
<?php
/**
* Glob all our JSON facets and register them
* with FacetWP
*/
function my_register_facets( $facets ) {
$new_facets_raw = glob(dirname(__FILE__) . '/facets/*.json'); // Or however you want to get your facet definitions
$new_facets = [];
foreach($new_facets_raw as $facet) {
$facet = json_decode(file_get_contents($facet), true);
$new_facets[] = $facet;
}
// Important: Put facets at the front of the array so they get added before db-based ones
return array_merge($new_facets, $facets);
}
add_filter( 'facetwp_facets', 'my_register_facets' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment