Last active
February 26, 2020 16:34
-
-
Save djrmom/7f2cf4a10600d6868f5b8badb52cadbe to your computer and use it in GitHub Desktop.
facetwp no results output for layout builder
This file contains 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 | |
/** | |
** 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Jenny!