1. Customize
  2. Transfers
  3. Filter recipients by a specific meta

Filter recipients by a specific meta

The following snippet shows how to filter recipients on any transfer form recipients autocomplete based on a specific meta value.

If you don’t know exactly the name of a meta key, you can use a plugin like JSM’s Show User Meta to see all stored user meta keys.

function my_prefix_filter_transfers_recipients_by_meta( $query_vars, $user_id, $search ) {

    global $wpdb;

    $meta_key = 'your_meta_key';        // Set the meta key you want to filter
    $meta_value = 'Your meta value';    // Set the meta value you want to filter
    $compare = '=';                     // Accepted values: =, !=, >, <, >=, <=

    $query_vars['join'][] = "LEFT JOIN {$wpdb->usermeta} AS umeta ON ( umeta.user_id = u.ID )";
    $query_vars['where'][] = "(  umeta.meta_key = '{$meta_key}' AND umeta.meta_value {$compare} '{$meta_value}' )";

    return $query_vars;

}
add_filter( 'gamipress_transfers_users_autocomplete_pre_query_vars', 'my_prefix_filter_transfers_recipients_by_meta', 10, 3 );
Was this article helpful to you? Yes No

How can we help?