Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*<!-- AUTHOR DROPDOWN --> */
- add_filter('relevanssi_hits_filter', 'rlv_gather_authors', 99);
- function rlv_gather_authors($hits) {
- global $rlv_author_present;
- $rlv_author_present = array();
- foreach ( $hits[0] as $hit ) {
- $terms = get_the_terms( $hit->ID, 'author' );
- if (is_array($terms)) {
- foreach ( $terms as $term ) {
- $rlv_author_present[ $term->term_id ] = $term->name;
- }
- }
- }
- asort( $rlv_author_present );
- return $hits;
- }
- function rlv_author_dropdown() {
- global $rlv_author_present, $wp_query;
- if (!empty($wp_query->query_vars['author'])) {
- $url = esc_url(remove_query_arg('author'));
- echo "<p><a href='$url'>Remove author filter</a>.</p>";
- }
- else {
- $select = "<select class='select' id='rlv_author' name='rlv_author'><option value=''>Filter Results by Author</option>";
- foreach ( $rlv_author_present as $author_id => $author_name ) {
- $select .= "<option value='$author_id'>$author_name</option>";
- }
- $select .= "</select>";
- $url = esc_url(remove_query_arg('paged'));
- if (strpos($url, 'page') !== false) {
- $url = preg_replace('/page\/\d+\//', '', $url);
- }
- $select .= <<<EOH
- <script>
- <!--
- var dropdown = document.getElementById("rlv_author");
- function onAuthorChange() {
- if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
- location.href = "$url"+"&author="+dropdown.options[dropdown.selectedIndex].value;
- }
- }
- dropdown.onchange = onAuthorChange;
- -->
- </script>
- EOH;
- echo $select;
- }
- }
- /*<!-- /AUTHOR DROPDOWN -->*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement