Support

Account

Home Forums Backend Issues (wp-admin) Display custom field in relationship field selection

Helping

Display custom field in relationship field selection

  • Hi, i have a custom post type called medecin, in this custom post type i added custom field (last_name, speciality etc), in a page i added a relationship custom field called medecins that is filtered by post type medecin.

    In the relationship field i only have the title showing (which represent the firstname) but several can have the same first name, how can i add at least the last name or event the speciality to make it clearer which one it is ?

    i tried the folowing:

    function my_relationship_result( $title, $post, $field, $post_id ) {
    
    	// load a custom field from this $object and show it in the $result
    	$lastname = get_field('last_name', $post->ID);
    
    	// append to title
    	$title .= ' [' . $lastname.  ']';
    
    	// return
    	return $title;
    
    }
    
    // filter for every field
    add_filter('acf/fields/relationship/result/name=medecins', 'my_relationship_result', 10, 4);

    But all i get is still the title + []

    Any idea ?

  • Sorry, found my mistake… dont see any option to delete the post.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Display custom field in relationship field selection’ is closed to new replies.