Last active
February 3, 2020 10:09
-
-
Save mahfelwp/97e71bb986e33fe99b851dc378f6dc43 to your computer and use it in GitHub Desktop.
Include users only with "yz_account_verified" ##meta_key and "on" ##meta_value on members directory at Youzer plugin and also buddypress
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 | |
/** | |
* Members Directory - Include Users By Meta_key & Meta_value | |
*/ | |
function yz_include_members_directory_by_verified( $loop ) { | |
if ( ! bp_is_members_directory() ) { | |
return $loop; | |
} | |
// Set Meta key & Meta value | |
$meta_key = 'yz_account_verified'; | |
$meta_value = 'on'; | |
// Get Users List | |
$users = get_users( array( 'meta_key'=> $meta_key, 'meta_value' => $meta_value ) ); | |
if ( empty( $users ) ) { | |
return $loop; | |
} | |
// Get User Ids | |
$users_ids = wp_list_pluck( $users, 'ID' ); | |
// Get Users Ids separated by "," | |
$users_ids = implode( ',', $users_ids ); | |
if ( isset( $loop['include'] ) && ! empty( $loop['include'] ) ) { | |
$loop['include'] = $loop['include'] . ',' . $users_ids; | |
} else { | |
$loop['include'] = $users_ids; | |
} | |
return $loop; | |
} | |
add_filter( 'bp_after_has_members_parse_args', 'yz_include_members_directory_by_verified' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment