Last active
March 11, 2023 10:03
-
-
Save gmmedia/89efaf56b55fe659e5bedca678f68dd6 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Modify search query to ignore the search term in HTML comments. | |
* | |
* @param string $where The WHERE clause of the query. | |
* @param WP_Query $query The WP_Query instance (passed by reference). | |
* | |
* @return string The modified WHERE clause. | |
*/ | |
function bp_update_search_query( $where, $query ) { | |
if ( ! is_search() || ! $query->is_main_query() ) { | |
return $where; | |
} | |
global $wpdb; | |
$search_query = get_search_query(); | |
$search_query = $wpdb->esc_like( $search_query ); | |
$where .= " AND {$wpdb->posts}.post_content NOT REGEXP '<!--.*$search_query.*-->' "; | |
return $where; | |
} | |
add_filter( 'posts_where', 'bp_update_search_query', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment