Last active
May 23, 2020 02:35
-
-
Save RadGH/877ee20d99eee73fb0e933f199d4b8fb to your computer and use it in GitHub Desktop.
Remove duplicate users from WP_User_Query
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 | |
/** | |
* Fix duplicate users appearing in WP_User_Query by specifying an OR meta query. | |
* This solution makes no sense but it works. ¯\_(ツ)_/¯ | |
* | |
* See: | |
* 1. https://gist.github.com/RadGH/877ee20d99eee73fb0e933f199d4b8fb | |
* 2: https://wordpress.stackexchange.com/questions/220307/user-appears-twice-in-a-wp-user-query | |
* 3: https://core.trac.wordpress.org/ticket/17582 | |
* | |
* @param WP_User_Query $query | |
*/ | |
function fix_duplicate_user_query_99d4b8fb( $query ) { | |
if ( !empty($query->get('meta_query')) ) { | |
$query->set( 'meta_query', array( 'relation' => 'OR', $query->get('meta_query') ) ); | |
} | |
} | |
add_action( 'pre_get_users', 'fix_duplicate_user_query_99d4b8fb', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
References from above (as links):
https://wordpress.stackexchange.com/questions/220307/user-appears-twice-in-a-wp-user-query
https://core.trac.wordpress.org/ticket/17582