WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Авторские Темы для WordPress
функция не описана

ACF_Ajax_Query_Users::get_results() public ACF 5.7.2

Returns an array of results for the given args.

{} Это метод класса: ACF_Ajax_Query_Users{}

Хуки из метода
Возвращает

Массив.

Использование

$ACF_Ajax_Query_Users = new ACF_Ajax_Query_Users();
$ACF_Ajax_Query_Users->get_results( $args );
$args (обязательный)
-

Список изменений

С версии 5.7.2 Введена.

Код ACF_Ajax_Query_Users::get_results() ACF 5.9.1

<?php
function get_results( $args ) {
	$results = array();
	
	// Prepare args for quey.
	$args = $this->prepare_args( $args );
	
	// Get result groups.
	if( !empty( $args['role__in']) ) {
		$roles = acf_get_user_role_labels( $args['role__in'] );
	} else {
		$roles = acf_get_user_role_labels();
	}
	
	// Return a flat array of results when searching or when queriying one group only.
	if( $this->is_search || count($roles) === 1 ) {
	
		// Query users and append to results.
		$wp_user_query = new WP_User_Query( $args );
		$users = (array) $wp_user_query->get_results();
		$total_users = $wp_user_query->get_total();
		foreach( $users as $user ) {
			$results[] = $this->get_result( $user );
		}
		
		// Determine if more results exist.
		// As this query does not return grouped results, the calculation can be exact (">").
		$this->more = ( $total_users > count($users) + $args['offset'] );
		
	// Otherwise, group results via role.
	} else {
		
		// Unset args that will interfer with query results.
		unset( $args['role__in'], $args['role__not_in'] );
		
		// Loop over each role.
		foreach( $roles as $role => $role_label ) {
			
			// Query users (for this role only).
			$args['role'] = $role;
			$wp_user_query = new WP_User_Query( $args );
			$users = (array) $wp_user_query->get_results();
			$total_users = $wp_user_query->get_total();
			
			//acf_log( $args );
			//acf_log( '- ', count($users) );
			//acf_log( '- ', $total_users );
			
			// If users were found for this query...
			if( $users ) {
				
				// Append optgroup of results.
				$role_results = array();
				foreach( $users as $user ) {
					$role_results[] = $this->get_result( $user );
				}
				$results[] = array(
					'text'		=> $role_label,
					'children'	=> $role_results
				);
				
				// End loop when enough results have been found.
				if( count($users) === $args['number'] ) {
					
					// Determine if more results exist.
					// As this query does return grouped results, the calculation is best left fuzzy to avoid querying the next group (">=").
					$this->more = ( $total_users >= count($users) + $args['offset'] );
					break;
				
				// Otherwise, modify the args so that the next query can continue on correctly.
				} else {
					$args['offset'] = 0;
					$args['number'] -= count($users);
				}
			
			// If no users were found (for the current pagination args), but there were users found for previous pages...
			// Modify the args so that the next query is offset slightly less (the number of total users) and can continue on correctly.
			} elseif( $total_users ) {
				$args['offset'] -= $total_users;
				continue;
				
			// Ignore roles that will never return a result.
			} else {
				continue;
			}				
		}
	}
	
	/**
	 * Filters the query results.
	 *
	 * @date	21/5/19
	 * @since	5.8.1
	 *
	 * @param	array $results The query results.
	 * @param	array $args The query args.
	 * @param	ACF_Ajax_Query $query The query object.
	 */
	return apply_filters( "acf/ajax/query_users/results", $results, $args, $this );
}