searchwp\native\short_circuit
Since: 4.0.0
Table of Contents
Control whether SearchWP overrides native WordPress searches.
Parameters
Type | Parameter | Default | Since |
---|---|---|---|
Boolean | $enabled |
false |
4.0.0 |
\SearchWP\Query | $query |
The Query being run | 4.0.0 |
Examples
All hooks should be added to your custom SearchWP Customizations Plugin.
Prevent SearchWP from providing search results when a specific URL parameter exists
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 | |
// Prevent SearchWP from providing search results when a specific URL parameter exists. | |
add_filter( 'searchwp\native\short_circuit', function( $enabled, $query ) { | |
// If 'my-query-var' is set, short circuit SearchWP. | |
if ( isset( $_GET['my-query-var'] ) ) { | |
return true; | |
} | |
return $enabled; | |
}, 20, 2 ); |