Last active
September 27, 2020 08:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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