Skip to content

Instantly share code, notes, and snippets.

@tareq1988
Last active August 29, 2015 14:19
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 tareq1988/e0899d6561413652793b to your computer and use it in GitHub Desktop.
Save tareq1988/e0899d6561413652793b to your computer and use it in GitHub Desktop.
Search both in wp_usermeta table and wp_users table
<?php
/**
* Search both in wp_usermeta table and wp_users table
*
* By Default WordPress search usermeta and postmeta by using `AND`
* in SQL queries. This filter replaces the `AND` with `OR`. This facilitate
* to search both in user table columns OR user meta columns
*
* @author Tareq Hasan
*
* @param string $sql the SQL query
*
* @return string modified SQL Query
*/
function wedevs_search_meta_or( $sql ) {
$sql = preg_replace('/AND/', 'OR', $sql, 1);
return $sql;
}
add_filter( 'get_meta_sql', 'wedevs_search_meta_or' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment