Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display output Xprofile checkbox


  • agorafolk
    Participant

    @agorafolk

    Hello,
    I need to output the chekbox xprofile field into tags with class named by the output field (like <li class”option-1″>option 1<li class”option-2″>option 2, is it possible ? Actually, it’s output texts of the checkboxes, separated by a comma.
    Also, is it possible to output the unchecked boxes with a specific class ?
    Thank you a lot for your answer 🙂
    Have a nice day…
    Alice

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

  • Varun Dubey
    Participant

    @vapvarun

    @agorafolk You can achieve this by customizing your theme or creating a custom plugin to manipulate the output of the xprofile field data.

    // Assume $user_id is the ID of the user and $field_id is the ID of your checkbox field
    $selected_options = bp_get_profile_field_data( array( 'field' => $field_id, 'user_id' => $user_id ) );
    
    // Split the selected options into an array
    $options_array = explode(', ', $selected_options);
    
    foreach ( $options_array as $option ) {
        // Sanitize the option to create a valid CSS class
        $class_name = sanitize_title( $option );
        echo '<li class="option-' . esc_attr( $class_name ) . '">' . esc_html( $option ) . '</li>';
    }
    

    agorafolk
    Participant

    @agorafolk

    Thank you for your answer. I don’t have a customized theme, I use kleo child theme for my css, and not sure to be able to manipulate a template. Is it easy to create a plugin?
    Thank you a lot for your answer 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar