Forums Forums Search & Filter Pro Search by ACF Field sorted by Last Name custom field

Viewing 10 posts - 1 through 10 (of 15 total)
  • Anonymous
    #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?

    Trevor
    #223837

    If you have separate fields for first and last names, then I see no reason why you cannot do this. Did you try it?

    Trevor
    #223841

    Are you able to send me a live link/URL to your search page so I can take a look?

    Anonymous
    #223849
    This reply has been marked as private.
    Trevor
    #223858

    It is on the ‘Posts’ tab, select ‘Meta Value’ and the the key name. Remember that the REAL ACF fieldname does NOT begin with an underscore.

    Anonymous
    #223926

    Trevor,

    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
    #223930

    Ah. 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
    #223973

    Trevor,

    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);
    Trevor
    #223979

    I am guessing you need to fetch the original list (array) first and use that to see which ones to remove.

    Anonymous
    #223983

    Instead of writing my own Query as I did above, is there a way to just hook into the Query done by the plugin and reorder the filter options on the fly?

Viewing 10 posts - 1 through 10 (of 15 total)