Home Forums General Issues Relationship Field Filter by \'last_name\' Reply To: Relationship Field Filter by \'last_name\'

  • John,

    Again thank you. Although I had issues when I tried your function it led me to a solution that worked. I included my code below. Your code resulted in blank fields. It seems, although i am not sure why, that I had to use a parameter of “$object” and call “$object->ID” for each custom field. ~ Thanks again 😉

    add_filter('acf/fields/relationship/result/key=field_565de210b1c8c', 'my_relationship_result', 10, 4);
    function my_relationship_result( $result, $object, $field, $post ) {
    	// load a custom field from this $object and show it in the $result
    		$lname = get_field('last_name', $object->ID);
    		$fname = get_field('first_name', $object->ID);
                    $result =  $fname.' '.$lname;  
    		return $result;