User Display Name + Additional Custom fields
-
I am trying to display the User Name + additional information such as the users title, for example:
Dr. First_Name Last_Name PhD
When trying to add custom fields under Ultimate Member – Settings – General – User – User Display Name I chose Custom field(s).
Below then in Display Name Custom field(s) I type the following:
pre_title_dropdown,first_name,last_name,post_title_dropdown
The result looks like this:
a:1:{i:0;s:3:”Dr.”;} Barry White a:1:{i:0;s:3:”MSc”;}
pre_title_dropdown is the metakey where people can choose one combination for example Dr. or DDr. Any help how to correctly display it as “Dr. Barry White MSc”?
Thanks!
-
Hi @amuri4
You can try this code snippets below. This is only applicable for a single selected dropdown option:
add_filter("um_user_display_name_filter",function( $value, $user_id ){ if( um_is_core_page('user') ){ preg_match_all('\<code>"([^"]*)"\</code>', $value, $results); $pre_title = serialize( [ str_replace('"',"", $results[0][0] ) ] ); $post_title = serialize( [ str_replace('"',"", $results[0][1] ) ] ); $value = str_replace( $pre_title, str_replace('"',"", $results[0][0] ), $value ); $value = str_replace( $post_title, str_replace('"',"", $results[0][1] ), $value ); } return $value; },10, 2);Regards,
-
This reply was modified 4 years, 8 months ago by
Champ Camba.
Hi @amuri4
Something is wrong when pasting the code here. Please copying the codes from the link:
https://gist.github.com/champsupertramp/f079bfde3226db4d8de787a45807dc98Regards,
Hi @amuri4
…Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂
Regards,
Hi Champ Camba,
The snippet does not work for me 🙁 I also changed the metakey in the code from “pre_title” to “pre_title_dropdown” and it would not change anything on the site. Do you have any idea?
Thanks
Maybe because they are Multi-select Drop Down?
Use this code snippet and it works for both single and multi select dropdowns for pre- and post-titles on profile, account and member directory pages.
add_filter("um_user_display_name_filter", function( $value, $user_id ) { if ( UM()->options()->get( 'display_name_field' ) != '' ) { $fields = array_filter( preg_split( '/[,\s]+/', UM()->options()->get( 'display_name_field' ) ) ); $name = ''; foreach ( $fields as $field ) { if ( um_profile( $field ) ) { $title = maybe_unserialize( um_profile( $field ) ); if( is_array( $title )) $title = implode( ",", $title ); $name .= $title . ' '; } elseif ( um_user( $field ) && $field != 'display_name' && $field != 'full_name' ) { $name .= um_user( $field ) . ' '; } } return $name; } return $value; },10, 2);Install the code snippet in your child-theme functions.php file
or use the “Code Snippets” plugin.https://ww.wp.xz.cn/plugins/code-snippets/
-
This reply was modified 4 years, 8 months ago by
missveronica.
-
This reply was modified 4 years, 8 months ago by
missveronica.
-
This reply was modified 4 years, 8 months ago by
missveronica.
-
This reply was modified 4 years, 8 months ago by
missveronica.
I have now reported this bug for action by the UM developers:
Thank you very much Veronica, it now works!
-
This reply was modified 4 years, 8 months ago by
The topic ‘User Display Name + Additional Custom fields’ is closed to new replies.