Skip to content

Gists - FacetWP

Code snippets for FacetWP

Gists

Force search facet to return 0 results if the the minimum character limit isn’t met
7 years ago
<?php

// Add this to your (child) theme's functions.php

add_filter( 'facetwp_search_query_args', function( $args ) {
    if ( strlen( $args['s'] ) < 3 ) {
        $args['post__in'] = array( 0 ); // force no results to be returned
    }
    return $args;
});

Where does code go?

PHP

PHP code usually starts with <?php  and can go into your child theme’s functions.php file.

JavaScript

If the code starts with <script>, then you can paste it into a wp_head PHP hook as shown in this example.

CSS

Add to your (child) theme’s style.css file.

© 2025 Gists - FacetWP • Built with GeneratePress