Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Kamuran Bildircin

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 );

	}

}
2 years, 8 months ago
Stefan van den Dungen Gronovius
Developer

Can you tell me what you mean by can’t search in ACF fields?
Do you mean that your own hook does not work anymore or that you’re not able to use our Smart Filtering feature to search on the overview on one of the available ACF columns?

You can check if you’re not sorting or filtering on any column on the overview page. In that case, our plugin should not interfere with your hook and if it still does not work, there must be something with the hook. You could install the plugin Query Monitor and analyze the main query to see the complete query and what might cause the issue.

2 years, 8 months ago

You must be logged in to reply to this topic.