Forums › Forums › Search & Filter Pro › Search by ACF Field sorted by Last Name custom field
- This topic has 14 replies, 2 voices, and was last updated 5 years, 1 month ago by Trevor.
-
Anonymous(Private) October 16, 2019 at 5:49 pm #223828
We have a search form that uses an ACF field (attorneys) to do the filtering. We have it setup to sort by Value which renders the list in alpha order by first name of the title of the attorney. We would like to sort the list by attorney’s last name using a custom field of the ACF. Is this possible?
Anonymous(Private) October 17, 2019 at 2:30 pm #223926Trevor,
Thanks for the reply. However, I’m only looking to change the order of the Filter options down the left column for the Attorneys section. Right now they are alpha by title but we need it to be alpha by last name. I’m assuming I need to add something to my functions.php file to achieve this, but I’m just not sure what.
Trevor(Private) October 17, 2019 at 2:34 pm #223930Ah. If this is a custom field/post meta, you can manually re-order them (using drag and drop). This would have to be done each time you add an attorney.
Alternately, you can do it programmatically using one of our filters (but you may need to hire a coder to code it for you):
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
Anonymous(Private) October 17, 2019 at 5:53 pm #223973Trevor,
Thanks for the link. I’ve been able to add a function and it’s now displaying the Attorneys in the correct order but how do I get it to hide the attorneys without a post like it does by default? Right now it’s displaying all attorneys even if there’s no news associated to the attorney,
function sf_edit_author_field_order($input_object, $sfid) { if( $input_object['name'] == '_sfm_attorneys' ) { // requery the author list $my_query = new WP_Query( array( 'post_type' => 'attorney', 'meta_key' => 'wpcf-att_last', 'orderby' => 'meta_value', 'order' => 'ASC', 'showposts' => -1)); while ($my_query->have_posts()) : $my_query->the_post(); $att_first = types_render_field("att_first", array()); $att_last = types_render_field("att_last", array()); $theid = get_the_ID(); // go through users and get their user_nicename and display_name //foreach( $my_query as $user ) { $new_users[] = (object) array( 'attributes' => array( 'class' => 'sf-level-0' ), 'value' => $theid, 'label' => $att_last . ', ' . $att_first, 'count' => 1 ); endwhile; $input_object['options'] = $new_users; } return $input_object; } add_filter('sf_input_object_pre', 'sf_edit_author_field_order', 10, 2);
-
AuthorPosts