• Resolved karlinara

    (@karlinara)


    Hello,

    I use a custom profile form with custom fields. Some of the fields are checkboxes or multi-select with multiple values. On the edited profile page these values are displayed as comma-separated text. But I need them as a list. How can I achieve this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support andrewshu

    (@andrewshu)

    Hello @karlinara

    Sorry, I can’t understand your question. Could you attach a screenshot (Please erase or blur all data that is confidential on the screenshot)?

    Regards.

    Thread Starter karlinara

    (@karlinara)

    Hello @andrewsh,

    thank you for your reply.

    This is how the profile looks like when editing it. Thats fine.

    This is how it looks like on the profile page. The list of options are not formatted as a list, so you can’t distinguish one option from another.


    This is how it should look like, options formatted as <ul>-list.

    I hope things are getting clearer now.

    • This reply was modified 2 years, 7 months ago by karlinara.

    @karlinara

    You can try this code snippet to get a bullet list of checkbox and multiselect field values.

    add_filter( 'um_profile_field_filter_hook__', 'um_field_value_bullet_list', 10, 3 );
    
    function um_field_value_bullet_list( $value, $data, $type ) {
    
        if ( $type == 'multiselect' || $type == 'checkbox' ) {
    
            $meta_value_list = '<ul>';
            foreach( $value as $meta_value ) {
                $meta_value_list .= '<li>' . $meta_value . '</li>';
            }
            $meta_value_list .= '</ul>';
            return $meta_value_list;
        }
        return $value;
    }

    Install the code snippet into your active theme’s functions.php file
    or use the “Code Snippets” plugin.

    https://ww.wp.xz.cn/plugins/code-snippets/

    Thread Starter karlinara

    (@karlinara)

    Perfect! That works. Thanks a lot!

    @karlinara

    Thanks for your feedback.
    I have made a request to make this formatting as a default feature in UM.

    https://github.com/ultimatemember/ultimatemember/issues/1353

    @karlinara

    An update of the code snippet to avoid a PHP warning.

    add_filter( 'um_profile_field_filter_hook__', 'um_field_value_bullet_list', 10, 3 );
    
    function um_field_value_bullet_list( $value, $data, $type ) {
    
        if ( $type == 'multiselect' || $type == 'checkbox' ) {
    
            if( is_array( $value )) {
                $meta_value_list = '<ul>';
                foreach( $value as $meta_value ) {
                    $meta_value_list .= '<li>' . $meta_value . '</li>';
                }
                $meta_value_list .= '</ul>';
                return $meta_value_list;
            }
        }
        return $value;
    }
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Checkbox Output as List’ is closed to new replies.