/** * Prepare and return list of filter fields * * @return array */ public function get_filter_fields() { $fields = array(array('id' => 's', 'name' => __('Global Search', $this->get('domain')), 'placeholder' => __('Search', $this->get('domain')), 'type' => 'text'), array('id' => 'post_status', 'name' => __('Status', $this->get('domain')), 'type' => 'select_advanced', 'js_options' => array('allowClear' => false), 'options' => $this->get_post_statuses()), array('id' => 'author', 'name' => __('Author', $this->get('domain')), 'type' => 'select_advanced', 'js_options' => array('allowClear' => true), 'map' => array('class' => 'post'), 'options' => array(0 => __('All', ud_get_wp_property()->domain)) + (array) \WPP_F::get_users_of_post_type('property')), array('id' => 'property_type', 'name' => sprintf(__('%s Type', $this->get('domain')), \WPP_F::property_label('plural')), 'type' => 'select_advanced', 'js_options' => array('allowClear' => true), 'options' => array_merge(array('' => ''), ud_get_wp_property('property_types', array()))), array('id' => 'featured', 'name' => __('Featured', $this->get('domain')), 'type' => 'checkbox'), array('id' => 'post_date_min', 'name' => __('Added Date from', ud_get_wp_property()->domain), 'type' => 'date', 'js_options' => array('allowClear' => true), 'map' => array('class' => 'date_query', 'compare' => 'after')), array('id' => 'post_date_max', 'name' => __('Added Date to', ud_get_wp_property()->domain), 'type' => 'date', 'js_options' => array('allowClear' => true), 'map' => array('class' => 'date_query', 'compare' => 'before'))); $defined = array(); foreach ($fields as $field) { array_push($defined, $field['id']); } /** Add to filter Searchable Attributes */ $attributes = ud_get_wp_property('property_stats', array()); $searchable_attributes = ud_get_wp_property('searchable_attributes', array()); $search_types = ud_get_wp_property('searchable_attr_fields', array()); $entry_types = ud_get_wp_property('admin_attr_fields', array()); $search_schema = ud_get_wp_property('attributes.searchable', array()); foreach ($searchable_attributes as $attribute) { /** Ignore current attribute if field with the same name already exists */ if (in_array($attribute, $defined)) { continue; } /** * Determine if type is searchable: * * Attribute must: * - have 'Data Entry' * - have 'Search Input' * - be searchable * - have valid 'Search Input'. See schema: ud_get_wp_property('attributes.searchable', array()) */ if (empty($entry_types[$attribute]) || empty($search_schema[$entry_types[$attribute]]) || !in_array($search_types[$attribute], $search_schema[$entry_types[$attribute]])) { continue; } $type = $search_types[$attribute]; $options = array(); $map = array(); /** Maybe Convert input types to valid ones and prepare options. */ switch ($type) { case 'input': $type = 'text'; $map = array('compare' => 'LIKE'); break; case 'range_input': case 'range_dropdown': case 'advanced_range_dropdown': case 'dropdown': $values = \WPP_F::get_all_attribute_values($attribute); $type = 'select_advanced'; break; case 'multi_checkbox': $values = \WPP_F::get_all_attribute_values($attribute); $type = 'checkbox_list'; break; } if (!empty($values)) { $options = array('' => ''); foreach ($values as $value) { $options[$value] = $value; } } array_push($fields, array_filter(array('id' => $attribute, 'name' => $attributes[$attribute], 'type' => $type, 'js_options' => array('allowClear' => true), 'options' => $options, 'map' => $map))); } $fields = apply_filters('wpp::overview::filter::fields', $fields); return $fields; }