I'm trying to set a limit on the numbers of letters user can add to their xprofile fields in their BuddyPress profiles.

For example, in BIO field, max limit will be 300 letters.

Please give me complete code if you can, because I have read lots of article about it but couldn't manage to find a code that works.

Thank you, Shay.

  • Check out my answer at wordpress.stackexchange.com/a/262572/66711 - you can use a similar approach, just count the characters in $values instead of querying for identical values.
    – user66711
    Apr 6, 2017 at 14:19
  • Alternatively if you have a custom field type you can try defining BP_XProfile_Field_Type::$validation_regex with a regex like /^.{0,300}$/.
    – user66711
    Apr 6, 2017 at 14:25

1 Answer 1


Try this code, if it will helps:

function filtered_profile_data( $args ) {

$data = bp_get_member_profile_data( $args );

$defaults = array(
    'field' => false, // Field name
    'user_id' => $user_id

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

switch($field) {
    case 'Field Name': // for specific field character limit
    $max_len = 10;
    $max_len = 5;

echo substr( $data, 0, $max_len);

  • Hi! thank you for replying! but i couldn't figure out where should I change the code to my field details and how.. and does it applies on BP xProfile fields plugin?
    – Shay S
    Apr 9, 2017 at 9:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.