Forums › Forums › Search & Filter Pro › Author Dropdown by Last Name
Tagged: author by last name
- This topic has 1 reply, 2 voices, and was last updated 4 years, 2 months ago by Trevor.
-
Anonymous(Private) September 9, 2020 at 4:58 pm #258945
I cannot figure out how to get the author dropdown to list them by last name.
I have a dropdown that does that in another part of our site using this script:
function authors_dropdown()
{
// Exclusion list. This could be passed as parameter to this function.
$excluded = array( ’14’, ’54’ );// Get authors to list.
add_filter( ‘authorship/user/roles’, ‘filter_user_role’ );
$authors = molongui_get_authors( ‘users’, array(), $excluded, array(), array(), ‘asc’, ‘last_name’ );
remove_filter( ‘authorship/user/roles’, ‘filter_user_role’ );?>
<select name=”author-dropdown” id=”author-dropdown–1″ class=”select-css” onchange=”javascript: this.value && (location.href = this.value);”>
<option value=””><?php echo esc_attr( __( ‘MEET OUR CONTRIBUTORS’ ) ); ?></option>
<?php foreach( $authors as $author ) : ?>
<?php $class = new Molongui\Authorship\Includes\Author( $author[‘id’], $author[‘type’] ); ?>
<option value=”<?php echo $class->get_url(); ?>” data-author-id=”<?php echo $author[‘id’]; ?>” data-author-type=”<?php echo $author[‘type’]; ?>”><?php echo $author[‘name’]; ?></option>
<?php endforeach; ?>
</select><?php
}How can I get the Search & Filter Pro dropdown to behave the same way?
Trevor(Private) September 10, 2020 at 8:28 am #258991The field in the form fetches the Author’s user ID from the posts, and fetches the user name from the User table, but fetches only the full name, and has no access (at that point) to the last name.
To do what you want, you would need to code the sorting yourself and use this filter to re-order the list;
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
There are many snippets in the forum that use this filter, and this post may be (or may be close to) what you want:
https://support.searchandfilter.com/forums/topic/sort-author-dropdown-by-last-name/#post-152293
-
AuthorPosts