Created
May 15, 2018 20:48
-
-
Save brlafreniere/03f41562e0e056089d12c245fe19eb5e 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
add_action( 'pre_get_posts', function( $q ) | |
{ | |
if( $title = $q->get( '_meta_or_title' ) ) | |
{ | |
add_filter( 'get_meta_sql', function( $sql ) use ( $title ) | |
{ | |
global $wpdb; | |
// Only run once: | |
static $nr = 0; | |
if( 0 != $nr++ ) return $sql; | |
// Modified WHERE | |
$sql['where'] = sprintf( | |
" AND ( %s OR %s ) ", | |
$wpdb->prepare( "{$wpdb->posts}.post_title like '%%%s%%'", $title), | |
mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) ) | |
); | |
return $sql; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment