BP_REST_XProfile_Fields_Endpoint::get_member_type_options( BP_XProfile_Field $field, array $request )
Get Profile field options
Description
Parameters
- $field
-
(BP_XProfile_Field) (Required) XProfile field object.
- $request
-
(array) (Required) request argument.
Return
(array)
Source
File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php
public function get_member_type_options( $field, $request ) { $posts = new \WP_Query( array( 'posts_per_page' => - 1, 'post_type' => bp_get_member_type_post_type(), 'orderby' => 'title', 'order' => 'ASC', ) ); $member_type = bp_get_member_type( ! empty( $request['user_id'] ) ? (int) $request['user_id'] : get_current_user_id() ); if ( '' !== $member_type ) { $post_selected = bp_member_type_post_by_type( $member_type ); } $options = array(); if ( $posts ) { foreach ( $posts->posts as $post ) { $enabled = get_post_meta( $post->ID, '_bp_member_type_enable_profile_field', true ); $name = get_post_meta( $post->ID, '_bp_member_type_label_singular_name', true ); $key = get_post_meta( $post->ID, '_bp_member_type_key', true ); if ( '' === $enabled || '1' === $enabled ) { $options[] = array( 'id' => $post->ID, 'group_id' => $field->group_id, 'parent_id' => $field->id, 'type' => 'option', 'name' => $name, 'key' => $key, 'description' => '', 'is_required' => '0', 'is_default_option' => ( $post_selected === $post->ID ), ); } } } return $options; }
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.