• Resolved rrsandler29

    (@rrsandler29)


    I want to create a custom Member Directory that displays only members that have “Role 1” AND “Role 2”. The only logic I can see is that the plugin will display member that are either “Role 1” OR “Role 2”.

    How can I accomplish this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • missveronica

    (@missveronicatv)

    @rrsandler29

    You can try this code snippet and test if it works OK for your Directory.

    add_filter( 'um_prepare_user_query_args', 'um_prepare_user_query_args_inclusive_roles', 10, 2 );
    
    function um_prepare_user_query_args_inclusive_roles( $query_args, $directory_data ) {
    
        if ( $directory_data['mode'] == 'directory' ) {
            $query_args['role'] = $query_args['role__in'];
            unset( $query_args['role__in'] );
        }
    
        return $query_args;
    }

    Install by adding the code snippet to your active theme’s functions.php file
    or use the “Code Snippets” Plugin

    https://wordpress.org/plugins/code-snippets/

    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hello @rrsandler29

    Try a code snippet that missveronica suggested if the “Custom usermeta table” setting is turned off. This solution may work because according to documentation the role parameter is an inclusive list: users must match *each* role.

    You can try this code snippet if the “Custom usermeta table” setting is turned on.

    add_action( 'um_pre_users_query', 'um_pre_users_query_inclusive_roles', 10, 2 );
    function um_pre_users_query_inclusive_roles( &$mdm, $directory_data ){
    global $wpdb;
    if ( ! empty( $mdm->roles ) && is_array( $mdm->where_clauses ) ) {
    foreach( $mdm->where_clauses as $i => $where_clause ) {
    if ( strpos( $where_clause, 'umm_roles.um_value LIKE' ) ) {
    $roles_clauses = array();
    foreach ( $mdm->roles as $role ) {
    $roles_clauses[] = $wpdb->prepare( 'umm_roles.um_value LIKE %s', '%"' . $wpdb->esc_like( $role ) . '"%' );
    }
    $mdm->where_clauses[ $i ] = '( ' . implode( ' AND ', $roles_clauses ) . ' )';
    }
    }
    }
    }

    Regards

    Plugin Support andrewshu

    (@andrewshu)

    Hi @rrsandler29

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.