Skip to:
Content
Pages
Categories
Search
Top
Bottom

profile fields by id


  • Horoshiy
    Participant

    @horoshiy

    Good day!

    is there a way to call profile fields by id, but not only data in the field but an input_name, name, description, etc.
    function “echo xprofile_get_field_data( $field_name_or_id [, optional $user_id] );” echoes just data and nothing more.

    Maybe I should rewrite function bp_the_profile_field() to bp_the_profile_field_byid( $field_id, $userid=null ); or there is another way?

    thanks in advance…

    Dmitriy.

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

  • Boone Gorges
    Keymaster

    @boonebgorges

    Yes, you can do this with the xprofile template functions, which are located at buddypress/bp-xprofile/bp-xprofile-templatetags.php. Use the profile loops in buddypress/bp-themes/bp-default/members/single/profile/profile-loop.php as a template.


    Horoshiy
    Participant

    @horoshiy

    no-no-no… I think you didn’t understand me… I need to get field name by id but there is NO function

    “xprofile_get_field_NAME( $field_name_or_id [, optional $user_id] )”

    such as “xprofile_get_field_DATA( $field_name_or_id [, optional $user_id] )” which exists.


    Boone Gorges
    Keymaster

    @boonebgorges

    I understand your question, and you’re right, there is no such function. But from inside of a profile loop, you can use bp_the_profile_field_name(), and it will get the $field_id implicitly from the loop iteration.

    If you don’t want to build a loop, you can get the field name from the $field_id like this:

    $field = new BP_XProfile_Field( $field_id );
    $field_name = $field->name;


    Horoshiy
    Participant

    @horoshiy

    Maybe I should be more concrete. My main task is to get profile fields structured inside the profile page. I need to place fields in 3 columns and in right order. So let’s imagine that we have 9 fields: Login, email, password, First Name, Last Name, Middle Name, Country, City, Address, Place of birth, Date of birth. I need to place Login, E-mail and Password in the first column in the page, First name, Last name and Middle name in the second column and Country, City, Address, Place of birth and Date of birth in the third column.
    So i have field id’s which i can place in my profile page.

    Should i do it like this?


    echo '

    ';
    $field = new BP_XProfile_Field( '1' );
    $field_name = $field->name;
    $field_value = $field->value;
    echo '

    ' . $field_name . ': ' . $field_value . '

    ';

    $field = new BP_XProfile_Field( '2' );
    $field_name = $field->name;
    $field_value = $field->value;
    echo '

    ' . $field_name . ': ' . $field_value . '

    ';

    $field = new BP_XProfile_Field( '3' );
    $field_name = $field->name;
    $field_value = $field->value;
    echo '

    ' . $field_name . ': ' . $field_value . '';

    echo '

    ';
    /* and so on */

    am I right?


    Boone Gorges
    Keymaster

    @boonebgorges

    That will work. The only problem is that it’s not entirely future-proof. If the structure of the $field object changes in future versions of BP, you’ll have to rewrite the code.

    If I were you, I would use a profile loop, as described at https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-profile-data-loop-bp_has_profile/. That way you can use the built-in template tags, which won’t break when BP is upgraded.

    The xprofile template tags aren’t as fleshed out as I wish they were, but they should work nicely for your purpose. Put the three fields that you want to appear in column 1 in a profile field group, the next three fields in another group, etc. Then it’ll be easy to create the markup using bp_profile_groups() loop.


    Horoshiy
    Participant

    @horoshiy

    ok, thank you for help! I’ll do it by grouping, it’ll be better…


    Boone Gorges
    Keymaster

    @boonebgorges

    Cool, good luck!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘profile fields by id’ is closed to new replies.
Skip to toolbar