All Topics
No longer search in AFC fields
Hi, I can (no longer) search in AFC fields. This worked in a previous ac-version (I haven’t used the feature for a long time and only see it now). Here my function. ACF-Field ist mak. Do you have any idea what the problem could be? Thank You.
add_action( 'pre_user_query', 'my_pre_user_search' );
function my_pre_user_search( $u_query ) {
global $wpdb, $my_globals;
$mu_admins = $my_globals['mu_admins'];
$mu_supporter = $my_globals['mu_supporter'];
$ff_supporter = $my_globals['hide_user'];
$hide_user = $my_globals['ff_supporter'];
$ff_hidden_user = array_merge( $mu_admins, $mu_supporter, $ff_supporter, $hide_user );
$current_user_id = get_current_user_id();
$query = "WHERE 1=1 ";
if ( in_array( $current_user_id, $mu_admins ) ) {
// no limits
$u_query->query_from .= " JOIN {$wpdb->usermeta} lname ON lname.user_id = {$wpdb->users}.ID AND lname.meta_key = 'last_name'";
$u_query->query_from .= " JOIN {$wpdb->usermeta} mak ON mak.user_id = {$wpdb->users}.ID AND mak.meta_key = 'mak' ";
$search_by = [ 'user_login', 'user_email', 'lname.meta_value', 'mak.meta_value' ];
$u_query->query_where = "WHERE 1=1 AND " . $u_query->get_search_sql( $search_query, $search_by, 'both' );
} else if ( in_array( $current_user_id, $ff_supporter ) ) {
// must have a mak number
$u_query->query_from .= " JOIN {$wpdb->usermeta} lname ON lname.user_id = {$wpdb->users}.ID AND lname.meta_key = 'last_name'";
$u_query->query_from .= " JOIN {$wpdb->usermeta} mak ON mak.user_id = {$wpdb->users}.ID AND mak.meta_key = 'mak' ";
$search_by = [ 'user_login', 'user_email', 'lname.meta_value', 'mak.meta_value' ];
$u_query->query_where = "WHERE 1=1 AND mak.meta_value != '' " . $u_query->get_search_sql( $search_query, $search_by, 'both' );
} else {
$query = "";
$ids = [];
foreach ( $ff_hidden_user as $hidden_user_id ) {
if ( in_array( $hidden_user_id, $ids ) ) {
} else {
if ( $hidden_user_id > 0 ) {
$query .= "AND {$wpdb->users}.ID<>$hidden_user_id ";
array_push( $ids, $hidden_user_id );
}
}
}
$u_query->query_where = str_replace( 'WHERE 1=1', "WHERE 1=1 $query", $u_query->query_where );
}
}
You must be logged in to reply to this topic.