function wpv_users_query_usermeta_filters( $args, $view_settings ) {
	
	global $WP_Views, $no_parameter_found;
	
	$usermeta_queries = array();
	$view_id = $WP_Views->get_current_view();
	foreach ( $view_settings as $index => $value ) {
		if ( preg_match( "/usermeta-field-(.*)_type/", $index, $match ) ) {
			$field = $match[1];
			$type = $value;
			$compare = $view_settings['usermeta-field-' . $field . '_compare'];
			$value = $view_settings['usermeta-field-' . $field . '_value'];
			
			/**
			* Filter wpv_resolve_variable_values
			*
			* @param $value the value coming from the View settings filter after passing through the check for URL params, shortcode attributes and date functions comparison
			* @param $resolve_attr Array containing the filters that need to be applied as resolvers
			*
			* @since 1.8.0
			*/
			
			$resolve_attr = array(
				'filters' => array( 'url_parameter', 'shortcode_attribute', 'date_timestamp', 'framework_value' )
			);
			$value = apply_filters( 'wpv_resolve_variable_values', $value, $resolve_attr );
			
			/**
			* Filter wpv_filter_usermeta_field_filter_type
			*
			* @param $type the type coming from the View settings filter: <CHAR>, <NUMERIC>, <BINARY>, <DATE>, <DATETIME>, <DECIMAL>, <SIGNED>, <TIME>, <UNSIGNED>
			* @param $field the key of the usermeta field being used to filter by
			* @param $view_id the ID of the View being displayed
			*
			* @since 1.8.0
			*/
			
			$type = apply_filters( 'wpv_filter_usermeta_field_filter_type', $type, $field, $view_id );
			
			$has_meta_query = wpv_resolve_meta_query( $field, $value, $type, $compare );
			if ( $has_meta_query ) {
				$usermeta_queries[] = $has_meta_query;
			}
		}
	}
	//Set usermeta relation
    if ( count( $usermeta_queries ) ) {
		$args['meta_query'] = $usermeta_queries;
        $args['meta_query']['relation'] = isset( $view_settings['usermeta_fields_relationship'] ) ? $view_settings['usermeta_fields_relationship'] : 'AND';
    }
	
	return $args;
}
function wpv_filter_post_custom_field($query, $view_settings)
{
    global $WP_Views, $no_parameter_found;
    $meta_keys = array();
    $meta_queries = array();
    $view_id = $WP_Views->get_current_view();
    foreach (array_keys($view_settings) as $key) {
        if (strpos($key, 'custom-field-') === 0 && strpos($key, '_compare') === strlen($key) - strlen('_compare')) {
            if (empty($meta_keys)) {
                $meta_keys = $WP_Views->get_meta_keys();
            }
            $name = substr($key, 0, strlen($key) - strlen('_compare'));
            $name = substr($name, strlen('custom-field-'));
            $meta_name = $name;
            if (!in_array($meta_name, $meta_keys)) {
                // this is needed for fields with keys containing spaces - we map those spaces to underscores when creating the filter
                $meta_name = str_replace('_', ' ', $meta_name);
            }
            // TODO add filter here: what happens when a meta_name contains a space AND an underscore?
            // We need a final solution, I prefer to use a %%SPACE%% placeholder and avoid the above mapping (which we should keepfor backwards compatibility)
            $value = $view_settings['custom-field-' . $name . '_value'];
            /**
             * Filter wpv_filter_custom_field_filter_original_value
             *
             * @param $value the value coming from the View settings filter after passing through the check for URL params, shortcode attributes and date functions comparison
             * @param $meta_name the key of the custom field being used to filter by
             * @param $view_id the ID of the View being displayed
             *
             * $value comes from the View settings. It's a string containing a single-value or a comma-separated list of single-values if the filter needs more than one value (for IN, NOT IN, BETWEEN and NOT BETWEEN comparisons)
             * Each individual single-value element in the list can use any of the following formats:
             * (string|numeric) if the single-value item is fixed
             * (string) URL_PARAM(parameter) if the filter is done via a URL param "parameter"
             * (string) VIEW_PARAM(parameter) if the filter is done via a [wpv-view] shortcode attribute "parameter"
             * (string) NOW() | TODAY() | FUTURE_DAY() | PAST_DAY() | THIS_MONTH() | FUTURE_MONTH() | PAST_MONTH() | THIS_YEAR() | FUTURE_YEAR() | PAST_YEAR() | SECONDS_FROM_NOW() | MONTHS_FROM_NOW() | YEARS_FROM_NOW() | DATE()
             *
             * @since 1.4.0
             */
            $value = apply_filters('wpv_filter_custom_field_filter_original_value', $value, $meta_name, $view_id);
            /**
             * Filter wpv_resolve_variable_values
             *
             * @param $value the value coming from the View settings filter after passing through the check for URL params, shortcode attributes and date functions comparison
             * @param $resolve_attr Array containing the filters that need to be applied as resolvers
             *
             * @since 1.8.0
             */
            $resolve_attr = array('filters' => array('url_parameter', 'shortcode_attribute', 'date_timestamp', 'framework_value'));
            $value = apply_filters('wpv_resolve_variable_values', $value, $resolve_attr);
            /**
             * Filter wpv_filter_custom_field_filter_processed_value
             *
             * @param $value the value coming from the View settings filter after passing through the check for URL params, shortcode attributes and date functions comparison
             * @param $meta_name the key of the custom field being used to filter by
             * @param $view_id the ID of the View being displayed
             *
             * @since 1.4.0
             */
            $value = apply_filters('wpv_filter_custom_field_filter_processed_value', $value, $meta_name, $view_id);
            $type = $view_settings['custom-field-' . $name . '_type'];
            /**
             * Filter wpv_filter_custom_field_filter_type
             *
             * @param $type the type coming from the View settings filter: <CHAR>, <NUMERIC>, <BINARY>, <DATE>, <DATETIME>, <DECIMAL>, <SIGNED>, <TIME>, <UNSIGNED>
             * @param $meta_name the key of the custom field being used to filter by
             * @param $view_id the ID of the View being displayed
             *
             * @since 1.6.0
             */
            $type = apply_filters('wpv_filter_custom_field_filter_type', $type, $meta_name, $view_id);
            $compare = $view_settings['custom-field-' . $name . '_compare'];
            $has_meta_query = wpv_resolve_meta_query($meta_name, $value, $type, $compare);
            if ($has_meta_query) {
                $meta_queries[] = $has_meta_query;
            }
        }
    }
    //Set usermeta relation
    if (count($meta_queries)) {
        $query['meta_query'] = $meta_queries;
        $query['meta_query']['relation'] = isset($view_settings['custom_fields_relationship']) ? $view_settings['custom_fields_relationship'] : 'AND';
    }
    return $query;
}