Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active February 26, 2020 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/7f2cf4a10600d6868f5b8badb52cadbe to your computer and use it in GitHub Desktop.
Save djrmom/7f2cf4a10600d6868f5b8badb52cadbe to your computer and use it in GitHub Desktop.
facetwp no results output for layout builder
<?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);
@JRockoford
Copy link

Brilliant! Is it possible to add to "No posts found" the search term searched? E.g. "No results were found for search term "khrfkhekheg." Thanks!

@jacobgorthy
Copy link

Brilliant! Is it possible to add to "No posts found" the search term searched? E.g. "No results were found for search term "khrfkhekheg." Thanks!

second this, please!

@jacobgorthy
Copy link

Thank you Jenny!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment