Last active
August 29, 2015 14:19
-
-
Save tareq1988/e0899d6561413652793b to your computer and use it in GitHub Desktop.
Search both in wp_usermeta table and wp_users table
This file contains hidden or 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 | |
/** | |
* 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