[ad_1]
@jonoman1
Replace the first line in your code snippet with this code for a number field:
add_action("um_view_field_value_number", function( $result, $data ){
Thanks, I tried this and it does save the “0” entry on the edit side now, but it still doesn’t show that field at all when viewing the profile page. Is there something else missing from the code?
@jonoman1
You can try this code snippet without your meta-key and all number fields are now displaying 0:
add_action("um_view_field_value_number", function( $result, $data ){
if( 0 == $result || '0' == trim( $result ) || empty( $result )) {
return "0 "; // Extra space required
}
return $result;
},10, 2);
Thank you! That seems to work in the profile area. It’s not showing up in the member directory on the profile card for fields with “0” so I wonder if this pulls from the metakey differently. If I wanted to put a “%” after the number would I put it into this code as well?
- This reply was modified 10 hours, 41 minutes ago by jonoman1.
@jonoman1
You need another code snippet for the Members Directory.
Where and how are you using this number field in the Members Directory?
@jonoman1
You can now replace the first code snippet and try this code snippet, where UM Members Directory will show “0” numbers and all numbers will have a % sign too.
add_filter( "um_ajax_get_members_data", "um_profile_number_members_data", 10, 3 );
function um_profile_number_members_data( $data_array, $user_id, $directory_data ) {
foreach ( UM()->builtin()->saved_fields as $key => $data ) {
if( $data['type'] == 'number' ) {
if ( in_array( $key, $directory_data['reveal_fields']) ||
in_array( $key, $directory_data['tagline_fields']) ||
in_array( $key, maybe_unserialize( $directory_data['search_fields'] )) ||
in_array( $key, maybe_unserialize( $directory_data['sorting_fields'] ))) {
if( !isset( $data_array[$key] )) {
$data_array[$key] = '0';
$data_array['label_' . $key] = UM()->fields()->get_label( $key );
}
$data_array[$key] .= '%';
}
}
}
return $data_array;
}
add_action( "um_view_field_value_number", function( $result, $data ) {
if( 0 == $result || '0' == trim( $result ) || empty( $result )) {
$result = "0";
}
return $result . '%';
},10, 2);
Great support! That works perfectly! Thank you so much for your time and expertise.
