Last active
April 16, 2021 06:44
-
-
Save champsupertramp/cb43f0d079b9160cd13238c75dd76257 to your computer and use it in GitHub Desktop.
Ultimate Member - UM Custom user query in Member Directory
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 | |
/** | |
* Show users with a Job Title "'WP Plugin developer " only | |
**/ | |
add_filter('um_prepare_user_query_args', 'um_my_custom_query_args', 99, 2); | |
function um_my_custom_query_args( $query_args, $args ) { | |
if( $args["form_id"] == "1" ) { // you can validate the current member directory form ID | |
$query_args['meta_query'][] = array( | |
"relation" => "OR", | |
array( | |
'key' => 'job_title', | |
'value' => serialize( 'WP Plugin developer' ), | |
'compare' => 'LIKE' | |
), | |
array( | |
'key' => 'job_title', | |
'value' => 'WP Plugin developer', | |
'compare' => '=' | |
) | |
); | |
} // endif | |
return $query_args; | |
} | |
?> |
Hi Everyone,
I'll be sharing some Ultimate Member customizations & tutorials on my website: www.champ.ninja
Subscribe to my newsletter to get the latest tutorials.
Regards,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have had a similar issue, and I found that the user query we were using was killed by two things. Firstly when querying for the users the query as passed to MySQL used SELECT DISTINCT SQL_CALC_FOUND_ROWS as well as ORDER BY RAND(). Both of these kill performance forcing MySQL to use temporary and filesort, if you are running on a server with HDD then your performance will die. As little as 5,000 users with several roles can mean a user look up can take nearly 60 seconds. Loading everything into foo_usermeta just kills performance; a pity that WP doesn't support PostgresQL, hstore is a godsend for that sort of thing.