facetwp no results output for layout builder

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/**
** displays alternate html when no posts are found
**/
add_filter( ‘facetwp_template_html’, function( $output, $class ) {
if ( $class->query->found_posts < 1 ) {
$output = ‘No posts found’;
// add below if you want to output any facets from the filters
// change my_facet_name to the name of your facet
if ( isset( FWP()->facet->facets[‘my_facet_name’] ) ) {
$keywords = FWP()->facet->facets[‘my_facet_name’][‘selected_values’];
$keywords = is_array( $keywords ) ? implode( ‘ ‘, $keywords ) : $keywords;
}
if ( !empty( $keywords ) ) {
$output .= ‘ for ‘ . $keywords;
}
}
return $output;
}, 10, 2);
{{/gist}}