Skip to content

Instantly share code, notes, and snippets.

@MWDelaney
Last active March 29, 2021 13:56
Show Gist options
  • Save MWDelaney/36b94b9774fef330d98c7ee616e61fa6 to your computer and use it in GitHub Desktop.
Save MWDelaney/36b94b9774fef330d98c7ee616e61fa6 to your computer and use it in GitHub Desktop.
<?php
// Add facets
add_filter('facetwp_facets', function () {
// Video category checkboxes
$facets[] = array(
'label' => 'Video Category',
'name' => 'video_category',
'type' => 'radio',
"source" => "tax/category",
"parent_term" => "",
"orderby" => "term_order",
"operator" => "and",
"hierarchical" => "no",
"ghosts" => "yes",
"preserve_ghosts" => "yes",
"count" => "10",
"soft_limit" => "5"
);
// Return the $facets array
return $facets;
});
// Insert facets before the appropriate loops
add_action('loop_start', function ($query) {
if ($query->is_post_type_archive('video')) {
echo '<div class="facet-container">';
echo facetwp_display('facet', 'video_category');
echo '</div>';
}
}, 10);
// Insert facetWP template markup before the appropriate loops
add_action('loop_start', function ($query) {
if ($query->is_post_type_archive('video')) {
echo '<div class="facetwp-template">';
}
}, 20);
// Close template loop
add_action('loop_end', function ($query) {
if ($query->is_post_type_archive('video')) {
echo '</div> <!-- /.facetwp-template -->';
}
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment