Skip to content

Instantly share code, notes, and snippets.

@brlafreniere
Created May 15, 2018 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brlafreniere/03f41562e0e056089d12c245fe19eb5e to your computer and use it in GitHub Desktop.
Save brlafreniere/03f41562e0e056089d12c245fe19eb5e to your computer and use it in GitHub Desktop.
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