Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created May 30, 2021 03:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/8af4f64df046d1aeaa659975229c64cb to your computer and use it in GitHub Desktop.
Save jchristopher/8af4f64df046d1aeaa659975229c64cb to your computer and use it in GitHub Desktop.
Tell SearchWP to exclude password protected results
<?php
// Tell SearchWP to exclude password protected results.
add_filter( 'searchwp\query\mods', function( $mods ) {
global $wpdb;
$mod = new \SearchWP\Mod();
$mod->set_local_table( $wpdb->posts );
$mod->on( 'ID', [ 'column' => 'id' ] );
$mod->raw_where_sql( function( $runtime ) {
return "LENGTH({$runtime->get_local_table_alias()}.post_password) = 0";
} );
$mods[] = $mod;
return $mods;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment