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 ago by Trevor.
-
Anonymous(Private) October 17, 2019 at 9:03 pm #224032
Trevor,
Thanks for all your help. I was able to find some code and have adapted it to work the way we need. It’s below incase you need it for anyone else
function filter_function_name($input_object, $sfid) { if ($input_object['name'] == '_sfm_attorneys') { global $coauthors_plus; // Update option labels before rendering foreach($input_object['options'] as $key => $option) { $my_query = new WP_Query( array( 'post_type' => 'attorney', 'p' => $option->value)); 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()); $input_object['options'][$key]->label = $att_last . ', ' . $att_first; endwhile; } // Sort options... $sortArray = array(); foreach($input_object['options'] as $option) { foreach($option as $key => $value) { if(!isset($sortArray[$key])) { $sortArray[$key] = array(); } $sortArray[$key][] = $value; } } // ...by label $orderby = "label"; array_multisort($sortArray[$orderby],SORT_ASC,$input_object['options']); } // Return return $input_object; } add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
-
AuthorPosts