Did you know that you can load FacetWP facets from a file instead of from the database? This way you can check them into version control. It works similar to the Advanced Custom Fields Local JSON feature!
Here’s how you accomplish it:
In your themes functions.php
/**
* FacetWP facets
*/
add_filter( 'facetwp_facets', function($facets) {
$imported_facets = json_decode(file_get_contents(trailingslashit(dirname(__FILE__)) . 'facetwp/facets.json'), true);
if(!isset($imported_facets['facets'])) {
return $facets;
}
foreach($imported_facets['facets'] as $single_facet) {
$facets[] = $single_facet;
}
return $facets;
});
In the facetwp/facets.json
you would put the FacetWP JSON export code, for example:
{
"facets": [
{
"label": "Search",
"name": "search",
"type": "search",
"search_engine": "relevanssi",
"placeholder": "Enter search terms"
},
{
"label":"Author",
"name":"author",
"type":"fselect",
"source":"post_author",
"multiple":"no",
"label_any":"Any",
"parent_term":"",
"orderby":"count",
"operator":"and",
"count":"1000"
}
]
}