function wpv_render_custom_field_options($args, $view_settings = null)
    {
        $compare = array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN');
        $types = array('CHAR', 'NUMERIC', 'BINARY', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED');
        if ($view_settings === null) {
            $value = '';
            $compare_selected = '';
            $type_selected = '';
            $name = 'custom-field-' . str_replace(' ', '_', $args['name']) . '%s';
            $parts = array($value);
        } else {
            $value = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_value'];
            $value = _wpv_encode_date($value);
            $compare_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_compare'];
            $compare_count = 1;
            $parts = array($value);
            switch ($compare_selected) {
                case 'BETWEEN':
                case 'NOT BETWEEN':
                    $compare_count = 2;
                    $parts = explode(',', $value);
                    // Make sure we have only 2 items.
                    while (count($parts) < 2) {
                        $parts[] = '';
                    }
                    while (count($parts) > 2) {
                        array_pop($parts);
                    }
                    break;
                case 'IN':
                case 'NOT IN':
                    $parts = explode(',', $value);
                    $compare_count = count($parts);
                    if ($compare_count < 1) {
                        $compare_count = 1;
                        $parts = array($value);
                    }
                    break;
            }
            $value = _wpv_unencode_date($value);
            $type_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_type'];
            $name = 'custom-field-' . str_replace(' ', '_', $args['name']) . '%s';
        }
        ?>
			<?php 
        _e('Comparison function:', 'wpv-views');
        ?>
			<p>
				<select name="<?php 
        echo sprintf($name, '_compare');
        ?>
" class="wpv_custom_field_compare_select js-wpv-custom-field-compare-select">
					<?php 
        foreach ($compare as $com) {
            $selected = $compare_selected == $com ? ' selected="selected"' : '';
            echo '<option value="' . $com . '" ' . $selected . '>' . $com . '&nbsp;</option>';
        }
        ?>
				</select>
				<select name="<?php 
        echo sprintf($name, '_type');
        ?>
" class="js-wpv-custom-field-type-select">
					<?php 
        foreach ($types as $type) {
            $selected = $type_selected == $type ? ' selected="selected"' : '';
            echo '<option value="' . $type . '" ' . $selected . '>' . $type . '&nbsp;</option>';
        }
        ?>
				</select>
			</p>

			<div class="js-wpv-custom-field-values">

				<?php 
        // This is where we store the actual value derived from the follow controls
        ?>
				<input type="hidden" class="js-wpv-custom-field-values-real" name="<?php 
        echo sprintf($name, '_value');
        ?>
" value="<?php 
        echo $value;
        ?>
" />

				<?php 
        for ($i = 0; $i < count($parts); $i++) {
            echo '<div class="wpv_custom_field_value_div js-wpv-custom-field-value-div">';
            $options = array();
            $options[__('Constant', 'wpv-views') . '&nbsp'] = 'constant';
            $options[__('URL parameter', 'wpv-views') . '&nbsp'] = 'url';
            $options[__('Shortcode attribute', 'wpv-views') . '&nbsp'] = 'attribute';
            $options['NOW&nbsp'] = 'now';
            $options['TODAY&nbsp;'] = 'today';
            $options['FUTURE_DAY&nbsp;'] = 'future_day';
            $options['PAST_DAY&nbsp;'] = 'past_day';
            $options['THIS_MONTH&nbsp;'] = 'this_month';
            $options['FUTURE_MONTH&nbsp;'] = 'future_month';
            $options['PAST_MONTH&nbsp;'] = 'past_month';
            $options['THIS_YEAR&nbsp;'] = 'this_year';
            $options['FUTURE_YEAR&nbsp;'] = 'future_year';
            $options['PAST_YEAR&nbsp;'] = 'past_year';
            $options['SECONDS_FROM_NOW&nbsp;'] = 'seconds_from_now';
            $options['MONTHS_FROM_NOW&nbsp;'] = 'months_from_now';
            $options['YEARS_FROM_NOW&nbsp;'] = 'years_from_now';
            $options['DATE&nbsp;'] = 'date';
            $function_value = _wpv_get_custom_filter_function_and_value($parts[$i]);
            echo wpv_form_control(array('field' => array('#name' => 'wpv_custom_field_compare_mode-' . $args['name'] . $i, '#type' => 'select', '#attributes' => array('style' => '', 'class' => 'wpv_custom_field_compare_mode js-wpv-custom-field-compare-mode'), '#inline' => true, '#options' => $options, '#default_value' => $function_value['function'])));
            echo '<input type="text" class="js-wpv-custom-field-value-text js-wpv-custom-field-' . $args['name'] . '-value-text" value="' . $function_value['value'] . '" data-class="js-wpv-custom-field-' . $args['name'] . '-value-text" data-type="none" name="js-wpv-custom-field-' . $args['name'] . '-value-text" />';
            // Add controls for entering the date.
            _wpv_custom_field_date_controls($function_value['function'], $function_value['value']);
            ?>
<input type="button" class="button-secondary js-wpv-custom-field-remove-value" value="<?php 
            echo __('Remove', 'wpv-views');
            ?>
">
						<?php 
            echo '</div>';
        }
        ?>
				<p>
					<input type="button" class="button-secondary js-wpv-custom-field-add-value" value="<?php 
        echo __('Add another value', 'wpv-views');
        ?>
"/>
				</p>

			</div>

	<?php 
    }
function wpv_add_meta_key($args, $view_settings = null)
{
    $compare = array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN');
    $types = array('CHAR', 'NUMERIC', 'BINARY', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED');
    if ($view_settings === null) {
        $value = '';
        $compare_selected = '';
        $type_selected = '';
        $name = 'custom-field-' . str_replace(' ', '_', $args['name']) . '%s';
        $parts = array($value);
    } else {
        $value = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_value'];
        $value = _wpv_encode_date($value);
        $compare_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_compare'];
        $compare_count = 1;
        $parts = array($value);
        switch ($compare_selected) {
            case 'BETWEEN':
            case 'NOT BETWEEN':
                $compare_count = 2;
                $parts = explode(',', $value);
                // Make sure we have only 2 items.
                while (count($parts) < 2) {
                    $parts[] = '';
                }
                while (count($parts) > 2) {
                    array_pop($parts);
                }
                break;
            case 'IN':
            case 'NOT IN':
                $parts = explode(',', $value);
                $compare_count = count($parts);
                if ($compare_count < 1) {
                    $compare_count = 1;
                    $parts = array($value);
                }
                break;
        }
        $value = _wpv_unencode_date($value);
        $type_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_type'];
        $name = '_wpv_settings[custom-field-' . str_replace(' ', '_', $args['name']) . '%s]';
    }
    ?>


	<div class="meta_key_div" style="margin-left: 20px;">
		<br />
		<?php 
    _e('Comparison function:', 'wpv-views');
    ?>
		<select name="<?php 
    echo sprintf($name, '_compare');
    ?>
" class="wpv_custom_field_compare_select">
			<?php 
    foreach ($compare as $com) {
        $selected = $compare_selected == $com ? ' selected="selected"' : '';
        echo '<option value="' . $com . '" ' . $selected . '>' . $com . '&nbsp;</option>';
    }
    ?>
		</select>
		<select name="<?php 
    echo sprintf($name, '_type');
    ?>
">
			<?php 
    foreach ($types as $type) {
        $selected = $type_selected == $type ? ' selected="selected"' : '';
        echo '<option value="' . $type . '" ' . $selected . '>' . $type . '&nbsp;</option>';
    }
    ?>
		</select>
		<br />
		
		<div class="wpv_custom_field_values">

			<?php 
    // This is where we store the actual value derived from the follow controls
    ?>
			<input type="hidden" name="<?php 
    echo sprintf($name, '_value');
    ?>
" value="<?php 
    echo $value;
    ?>
" />

			<?php 
    for ($i = 0; $i < count($parts); $i++) {
        echo '<div class="wpv_custom_field_value_div">';
        $options = array();
        $options[__('Constant', 'wpv-views') . '&nbsp'] = 'constant';
        $options[__('URL parameter', 'wpv-views') . '&nbsp'] = 'url';
        $options[__('Shortcode attribute', 'wpv-views') . '&nbsp'] = 'attribute';
        $options['NOW&nbsp'] = 'now';
        $options['TODAY&nbsp;'] = 'today';
        $options['FUTURE_DAY&nbsp;'] = 'future_day';
        $options['PAST_DAY&nbsp;'] = 'past_day';
        $options['THIS_MONTH&nbsp;'] = 'this_month';
        $options['FUTURE_MONTH&nbsp;'] = 'future_month';
        $options['PAST_MONTH&nbsp;'] = 'past_month';
        $options['THIS_YEAR&nbsp;'] = 'this_year';
        $options['FUTURE_YEAR&nbsp;'] = 'future_year';
        $options['PAST_YEAR&nbsp;'] = 'past_year';
        $options['SECONDS_FROM_NOW&nbsp;'] = 'seconds_from_now';
        $options['MONTHS_FROM_NOW&nbsp;'] = 'months_from_now';
        $options['YEARS_FROM_NOW&nbsp;'] = 'years_from_now';
        $options['DATE&nbsp;'] = 'date';
        $function_value = _wpv_get_custom_filter_function_and_value($parts[$i]);
        echo wpv_form_control(array('field' => array('#name' => 'wpv_custom_field_compare_mode-' . $args['name'] . $i, '#type' => 'select', '#attributes' => array('style' => '', 'class' => 'wpv_custom_field_compare_mode'), '#inline' => true, '#options' => $options, '#default_value' => $function_value['function'])));
        echo '<input type="text" class="wpv_custom_filter_value_text" value="' . $function_value['value'];
        if ($function_value['text_boxes'] == 1) {
            echo '" />';
        } else {
            echo '" style="display:none;" />';
        }
        ?>
					<span class="wpv_custom_field_param_missing"><?php 
        echo __('<- Please enter a value here', 'wpv-views');
        ?>
</span>
					<?php 
        // Add controls for entering the date.
        _wpv_add_date_controls($function_value['function'], $function_value['value']);
        // Add a "Remove" button
        echo '<input type="button" class="button-secondary wpv_custom_field_remove_value" value="' . __('Remove', 'wpv-views') . '" ';
        if ($i > 0 && ($compare_selected == 'IN' || $compare_selected == 'NOT IN')) {
            echo ' />';
        } else {
            echo 'style="display:none" />';
        }
        echo '</div>';
    }
    ?>
			<?php 
    $show = $compare_selected == 'IN' || $compare_selected == 'NOT IN' ? ' ' : 'style="display:none" ';
    ?>
			<input type="button" class="button-secondary wpv_custom_field_add_value" value="<?php 
    echo __('Add another value', 'wpv-views');
    ?>
" <?php 
    echo $show;
    ?>
/>
																								  
																								  
		</div>
		

	<?php 
    if ($view_settings == null) {
        ?>
		
		<br />
		<span class="wpv-custom-fields-help"><i>
			<?php 
        echo sprintf(__('%sLearn about filtering by custom fields%s', 'wpv-views'), '<a href="' . WPV_FILTER_BY_CUSTOM_FIELD_LINK . '" target="_blank">', ' &raquo;</a>');
        ?>
		</i></span>
	<?php 
    }
    ?>
	
	</div>
	

	<?php 
}