PATH:
home
/
letacommog
/
ldqm1
/
wp-content
/
plugins
/
facetwp
/
includes
/
facets
<?php class FacetWP_Facet_Dropdown extends FacetWP_Facet { function __construct() { $this->label = __( 'Dropdown', 'fwp' ); } /** * Load the available choices */ function load_values( $params ) { global $wpdb; $facet = $params['facet']; $from_clause = $wpdb->prefix . 'facetwp_index f'; // Facet in "OR" mode $where_clause = $this->get_where_clause( $facet ); // Orderby $orderby = $this->get_orderby( $facet ); $orderby = apply_filters( 'facetwp_facet_orderby', $orderby, $facet ); $from_clause = apply_filters( 'facetwp_facet_from', $from_clause, $facet ); $where_clause = apply_filters( 'facetwp_facet_where', $where_clause, $facet ); // Limit $limit = $this->get_limit( $facet, 20 ); $sql = " SELECT f.facet_value, f.facet_display_value, f.term_id, f.parent_id, f.depth, COUNT(DISTINCT f.post_id) AS counter FROM $from_clause WHERE f.facet_name = '{$facet['name']}' $where_clause GROUP BY f.facet_value ORDER BY $orderby LIMIT $limit"; return $wpdb->get_results( $sql, ARRAY_A ); } /** * Generate the facet HTML */ function render( $params ) { $output = ''; $facet = $params['facet']; $values = (array) $params['values']; $selected_values = (array) $params['selected_values']; if ( FWP()->helper->facet_is( $facet, 'hierarchical', 'yes' ) ) { $values = FWP()->helper->sort_taxonomy_values( $params['values'], $facet['orderby'] ); } $label_any = empty( $facet['label_any'] ) ? __( 'Any', 'fwp-front' ) : $facet['label_any']; $label_any = facetwp_i18n( $label_any ); $output .= '<select class="facetwp-dropdown">'; $output .= '<option value="">' . esc_attr( $label_any ) . '</option>'; foreach ( $values as $result ) { $selected = in_array( $result['facet_value'], $selected_values ) ? ' selected' : ''; $display_value = ''; for ( $i = 0; $i < (int) $result['depth']; $i++ ) { $display_value .= ' '; } // Determine whether to show counts $display_value .= esc_attr( $result['facet_display_value'] ); $show_counts = apply_filters( 'facetwp_facet_dropdown_show_counts', true, [ 'facet' => $facet ] ); if ( $show_counts ) { $display_value .= ' (' . $result['counter'] . ')'; } $output .= '<option value="' . esc_attr( $result['facet_value'] ) . '"' . $selected . '>' . $display_value . '</option>'; } $output .= '</select>'; return $output; } /** * Filter the query based on selected values */ function filter_posts( $params ) { global $wpdb; $facet = $params['facet']; $selected_values = $params['selected_values']; $selected_values = is_array( $selected_values ) ? $selected_values[0] : $selected_values; $sql = " SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index WHERE facet_name = '{$facet['name']}' AND facet_value IN ('$selected_values')"; return facetwp_sql( $sql, $facet ); } /** * Output admin settings HTML */ function settings_html() { $this->render_setting( 'label_any' ); $this->render_setting( 'parent_term' ); $this->render_setting( 'modifiers' ); $this->render_setting( 'hierarchical' ); $this->render_setting( 'orderby' ); $this->render_setting( 'count' ); } }
[+]
..
[-] slider.php
[edit]
[-] rating.php
[edit]
[-] radio.php
[edit]
[-] search.php
[edit]
[-] dropdown.php
[edit]
[-] fselect.php
[edit]
[-] base.php
[edit]
[-] number_range.php
[edit]
[-] date_range.php
[edit]
[-] checkboxes.php
[edit]
[-] autocomplete.php
[edit]
[-] hierarchy.php
[edit]
[-] proximity.php
[edit]
[-] pager.php
[edit]