BP_REST_XProfile_Repeater_Endpoint::get_repeater_fields( integer $field_id, integer $user_id, integer $group_id )

Get sub field using parent field ID and group ID.

Description

Parameters

$field_id

(Required) The profile field object ID.

$user_id

(Required) The ID of the user.

$group_id

(Required) The profile group object ID.

Return

(array|void)

Source

File: bp-xprofile/classes/class-bp-rest-xprofile-repeater-endpoint.php

853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
public function get_repeater_fields( $field_id, $user_id, $group_id ) {
    global $bp, $wpdb;
 
    if ( empty( $field_id ) || empty( $user_id ) ) {
        return;
    }
 
    // phpcs:ignore
    $sql = "select m1.object_id FROM {$bp->profile->table_name_meta} as m1 WHERE m1.meta_key = '_cloned_from' AND m1.meta_value = %d";
    // phpcs:ignore
    $sql = $wpdb->prepare( $sql, $field_id );
    // phpcs:ignore
    $results = $wpdb->get_col( $sql );
    $data    = array();
 
    $user_fields = bp_get_profile_field_set_count( $group_id, $user_id );
 
    if ( ! empty( $results ) && ! is_wp_error( $results ) ) {
 
        $count = 1;
 
        foreach ( $results as $k => $sub_field_id ) {
 
            if ( $count > $user_fields ) {
                break;
            }
 
            $data[ $sub_field_id ] = $count;
            $count++;
        }
    }
 
    return $data;
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.