function wpbdp_listing_sort_options() { $sort_options = array(); $sort_options = apply_filters('wpbdp_listing_sort_options', $sort_options); if (!$sort_options) { return ''; } $current_sort = wpbdp_get_current_sort_option(); $html = ''; $html .= '<div class="wpbdp-listings-sort-options wpbdp-hide-on-mobile">'; $html .= _x('Sort By:', 'templates sort', 'WPBDM') . ' '; foreach ($sort_options as $id => $option) { $default_order = isset($option[2]) && !empty($option[2]) ? strtoupper($option[2]) : 'ASC'; $html .= sprintf('<span class="%s %s"><a href="%s" title="%s">%s</a> %s</span>', $id, $current_sort && $current_sort->option == $id ? 'current' : '', esc_url($current_sort && $current_sort->option == $id ? add_query_arg('wpbdp_sort', ($current_sort->order == 'ASC' ? '-' : '') . $id) : add_query_arg('wpbdp_sort', ($default_order == 'DESC' ? '-' : '') . $id)), isset($option[1]) && !empty($option[1]) ? esc_attr($option[1]) : esc_attr($option[0]), $option[0], $current_sort && $current_sort->option == $id ? $current_sort->order == 'ASC' ? '↑' : '↓' : ($default_order == 'DESC' ? '↓' : '↑')); $html .= ' | '; } $html = substr($html, 0, -3); $html .= '<br />'; if ($current_sort) { $html .= sprintf('(<a href="%s" class="reset">%s</a>)', remove_query_arg('wpbdp_sort'), _x('Reset', 'sort', 'WPBDM')); } $html .= '</div>'; $html .= '<div class="wpbdp-listings-sort-options wpbdp-show-on-mobile">'; $html .= '<select class="">'; $html .= '<option value="0" class="header-option">' . _x('Sort By:', 'templates sort', 'WPBDM') . '</option>'; foreach ($sort_options as $id => $option) { $default_order = isset($option[2]) && !empty($option[2]) ? strtoupper($option[2]) : 'ASC'; $html .= sprintf('<option value="%s" %s>%s%s %s</option>', esc_url($current_sort && $current_sort->option == $id ? add_query_arg('wpbdp_sort', ($current_sort->order == 'ASC' ? '-' : '') . $id) : add_query_arg('wpbdp_sort', ($default_order == 'DESC' ? '-' : '') . $id)), $current_sort && $current_sort->option == $id ? 'selected="selected"' : '', str_repeat(' ', 3), $option[0], $current_sort && $current_sort->option == $id ? $current_sort->order == 'ASC' ? '↑' : '↓' : ($default_order == 'DESC' ? '↓' : '↑')); } if ($current_sort) { $html .= sprintf('<option value="%s" class="header-option">%s</option>', remove_query_arg('wpbdp_sort'), _x('(Reset)', 'sort', 'WPBDM')); } $html .= '</select>'; $html .= '</div>'; return $html; }
public function sortbar_orderby($orderby) { global $wpdb; $sort = wpbdp_get_current_sort_option(); if (!$sort || !in_array(str_replace('field-', '', $sort->option), wpbdp_get_option('listings-sortbar-fields'))) { return $orderby; } $sname = str_replace('field-', '', $sort->option); $qn = ''; switch ($sname) { case 'user_login': case 'user_registered': $qn = $sname; break; case 'date': case 'modified': $qn = "{$wpdb->posts}.post_{$sname}"; break; default: $field = wpbdp_get_form_field($sname); if (!$field) { break; } switch ($field->get_association()) { case 'title': case 'excerpt': case 'content': $qn = "{$wpdb->posts}.post_" . $field->get_association(); break; case 'meta': $qn = "field_{$sname}"; break; } break; } if ($qn) { return $orderby . ', ' . $qn . ' ' . $sort->order; } else { return $orderby; } }