Skip to:
Content
Pages
Categories
Search
Top
Bottom

New XProfile Field With A Loop

  • Avatar of TripWest
    TripWest
    Participant

    @tripwest

    Okay, so here is what I’m trying to do, but I’m not quite sure how to go about it.

    I want to create a new XProfile Field that contains a dropdown list of all members automatically (in other words, I want to use a loop. I don’t want to have to manually type in member names every single time somebody registers).

    Does anybody know how I would go about this? Or any shared tutorials would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Avatar of TripWest
    TripWest
    Participant

    @tripwest

    Alright, here’s where I am at. However, it seems to be riddled with errors. Anybody see anything glaringly wrong with my plugin? I’m getting parsing errors around line 7

    1,
    ‘type’ => ‘selectbox’,
    ‘name’ => ‘Featured Teacher’,
    ‘description’ => ‘Showcase your teacher on your Profile’,
    ‘is_required’ => false,
    ‘can_delete’ => true,
    ‘order_by’ => ‘name’
    );
    $featured_teacher_list_id = xprofile_insert_field($teacher_list_args);
    if ($featured_teacher_list_id) {
    $featured_teachers = array(

    while ( bp_members() ) : bp_the_member();
    $fitlinkzmembertype = xprofile_get_field_data(‘Member Type’, bp_get_member_user_id());
    if ($fitlinkzmembertype == ‘Teacher’) :
    bp_member_name();
    endif;
    endwhile;

    );
    foreach ($featured_teachers as $i =>$featured_teacher) {
    xprofile_insert_field(array(
    ‘field_group_id’ => 1,
    ‘parent_id’ => $featured_teacher_list_id,
    ‘type’ => ‘selectbox’, // it is ‘selectbox’ not ‘option’
    ‘name’ =>$featured_teacher,
    ‘option_order’ => $i+1
    ));
    }
    }
    }

    //Featured Group
    add_action(‘bp_member_meta_init’, ‘featured_group_list’); // That might not be the perfect hook to use
    function featured_group_list() {
    if (xprofile_get_field_id_from_name(‘Featured Group’)) return;
    $group_list_args = array(
    ‘field_group_id’ => 1,
    ‘type’ => ‘selectbox’,
    ‘name’ => ‘Featured Group’,
    ‘description’ => ‘Showcase your group on your Profile’,
    ‘is_required’ => false,
    ‘can_delete’ => true,
    ‘order_by’ => ‘name’
    );
    $featured_group_list_id = xprofile_insert_field($group_list_args);
    if ($featured_group_list_id) {
    $featured_groups = array(

    while ( bp_groups() ) : bp_the_group(); if(custom_field(‘fitlinkz-group-type’) == ‘Group’ ) :
    bp_group_name();
    endif;
    endwhile;

    );
    foreach ($featured_groups as $i =>$featured_group) {
    xprofile_insert_field(array(
    ‘field_group_id’ => 1,
    ‘parent_id’ => $featured_group_list_id,
    ‘type’ => ‘selectbox’, // it is ‘selectbox’ not ‘option’
    ‘name’ =>$featured_group,
    ‘option_order’ => $i+1
    ));
    }
    }
    }

    ?>

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    post code here https://gist.github.com

    Then give us the link to gist.

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

The topic ‘New XProfile Field With A Loop’ is closed to new replies.