Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can you run multiple profile loops in single/profile-loop.php ?

Viewing 21 replies - 1 through 21 (of 21 total)
  • @bofw

    Participant

    @pollyplummer DJPaul has a fair bit of knowledge in this area – I’ve been picking his brains for the last few weeks on this very issue lol @DJPaul a nudge for you mate as you may be able to point in the right direction.

    @djpaul

    Keymaster

    @bofw Ah, there you are. Was wondering when I’d find your username on here.

    Sarah – are you trying to hide particular fields, or field groups, on the ‘edit profile’ page?

    @pollyplummer

    Member

    Thanks for the recommendation @BOW. Paul – I’m trying to hide particular field groups on the edit page. I set the user type in a field group called “Accounts” (radio select Personal, Business, or Artist) which I have appended to the registration process. Then, based on their answer there I want to show or hide different field groups in the profile edit page and profile display page. I also want to hide the “Accounts” field group from everyone so that they can’t change that after registration.

    @boonebgorges

    Keymaster

    Inside of the while( bp_profile_groups() ) loop for each member, check to see if bp_the_profile_group_name() is one that should be displayed to that particular user. In other words, put the template markup inside of a big conditional:

    if ( bp_the_profile_group_name() == 'awesome' && get_usermeta( $bp->loggedin_user->id, 'awesome_user' ) ) {
    // Show the profile fields in the 'awesome' group only for those users with the usermeta 'awesome_user'
    }

    Do that for each user type and each profile field group. Only the right stuff will be displayed; groups not meeting the criteria will be hidden.

    @pollyplummer

    Member

    @Boone Gorges – thanks for putting me on the right track. I’m still not getting it right. Forgive me if this is really wonky:

    So I’m in the edit.php file and after this part:
    if ( bp_has_profile( ‘profile_group_id=’ . bp_get_current_profile_group_id() ) ) : while ( bp_profile_groups() ) : bp_the_profile_group();

    I have added the following:
    if ( bp_the_profile_group_name() == ‘personal’ && get_usermeta( $bp->loggedin_user->id, ‘114’ ) ) {
    ( bp_has_profile( ‘profile_group_id=1,3,4’ ) ) : while ( bp_profile_groups() ) : bp_the_profile_group();
    }

    The 114 is the meta_value for personal selection in the profile field wherein I ask them to select Personal, Business, or Artist. The profile group name ‘personal’ is one of the field groups that applies only to ‘personal’ accounts. (<- definitely not sure if I'm doing that right)
    I’m thinking I have a few things out of order…

    @boonebgorges

    Keymaster

    Hi @pollyplummer. You have basically got the right idea, but there are a few problems.

    First, your check for usermeta is not formatted correctly. See https://codex.wordpress.org/Function_Reference/get_usermeta for get_usermeta syntax. In any case, get_usermeta gets stuff from the wp_usermeta table, and I used it as an example in my code to give you a sense of the kind of check you’d want to do. But that’ll only work if you’re checking against a piece of data that is stored using update_usermeta. BP xprofile fields are not. If the “114” information is stored in a bp xprofile field, you will probably have to do some magic with xprofile_get_field() to get it to work. The following will check for a field called “Type” and check to see if the current user’s Type value is 114:

    $field_id = xprofile_get_field_id_from_name( 'Type' );
    $field = xprofile_get_field( $field_id );
    $value = $field->data->value;

    if ( bp_the_profile_group_name() == 'awesome' && $value == '114' ) {

    There’s probably a slicker way to do this, but it works. Again, this is only relevant if you’re storing the salient data in the xprofile tables.

    The second problem is that you don’t want to repeat the bp_has_profile etc stuff inside of the if statement. If you want to feed a profile_group_id argument to bp_has_profile, you should do it in the initial loop.

    Then make sure that you include the markup inside of the conditional if statement. In edit.php, that means everything, including the

    tag, that creates the markup enabling the user to edit that group of profile items.

    @ehegwer

    Participant

    Not to hijack, but I saw this and thought someone might have some suggestions for adding profile updates to the activity feed. (I’ve got custom fields, and want a notification to show up in the feed, when updated).

    @rogercoathup

    Participant

    @ehegwer – post your question as a separate thread, if you want users to find and answer it

    @ehegwer

    Participant

    @rogercoathup

    Participant

    cross reference is good – answered now!

    @janismo

    Participant

    `<?php
    $field_id = xprofile_get_field_id_from_name( ‘Type’ );
    $field = xprofile_get_field( $field_id );
    $value = $field->data->value;

    if ( bp_the_profile_group_name() == ‘Type’ && $value == ‘114’ ) {
    ( bp_has_profile( ‘profile_group_id=1,3,4′ ) ) : while ( bp_profile_groups() ) : bp_the_profile_group();
    }
    ?>`

    Full code, which should be placed in profile-loop.php,
    Did I understand correctly, what @boonebgorges tried to explain?
    @hnla please, take a look on this.

    thank you guys!

    @hnla

    Participant

    @janismo I’ve slightly lost track of what you are trying to do and need to reference the other threads, if this is running in a profile loop then I’m not sure there isn’t a simpler approach than this one outlined here (not sure you really need to do xprofile_get_field_id_from_name), but it’s late , I’m tired and not thinking clearly :(

    @boonebgorges

    Keymaster

    A couple things –

    – You need an `if` before `bp_has_profile`, eg `( if ( bp_has_profile( ‘profile_group_id=1,3,4’ ) ) ) :`
    – You’ll need to close the ifs and whiles; before the final `}` put `endwhile; endif;`
    – You need to actually display some content after bp_the_profile_group();. Look at the xprofile templates (bp-themes/bp-default/profile…) to get a sense of the template tags you’ll use inside of the loop to display content.

    @janismo

    Participant

    thnaks @boonebgorges ,
    somehow first place where I get mistake is your mentioned `if` before `bp_has_profile`
    taking all together I got this code for profile-loop.php :

    `

    <?php
    $field_id = xprofile_get_field_id_from_name( ‘Account Type’ );
    $field = xprofile_get_field( $field_id );
    $value = $field->data->value;

    if ( bp_the_profile_group_name() == ‘Account Type’ && $value == ‘Selection 1’ ) {
    (if ( bp_has_profile( ‘profile_group_id=1,4’ ) ) ?>

    <div class="bp-widget “>

    <tr>

    }

    `

    does this code make any sense for anyone?
    Am I correct, that even if I will get this code to work, it still returns only one selection of radio button?

    thank you!

    @janismo

    Participant

    @pollyplummer

    Sarah, couldn’t you share your experience re this question?
    please?

    @hnla

    Participant

    @janismo take a care asking everyone and their dog to look at your problem :) you must allow some time, generally the people that can help are pretty busy themselves.

    Last post I saw mention of ‘Can only get one value for radio button’ radio form controls can only be in one state or value, if you were needing to see if a profile should do something based on a number possible radio selections can you not do:

    if radio == ” || radio == ” || radio == ” it’s probably a little long winded and better done by doing something like an array compare or some other more elegant approach.

    @janismo

    Participant

    @hnla
    if you would look on the whole topic, you would see that discussion is about radio button with x selections, but discribed code includes only one selection, therefor my question seems a bit logical, as 60% of people here won’t be able to change code themselves (me too).
    people that were mentioned in previous posts were involved in this question, or those who would like to help.
    my problem? you could create poll to see, how many people would like to have this feature (I’ve seen last request few hours ago).

    definitely won’t disturb you any more, and your dog too :)

    thank you.

    @janismo

    Participant

    ok, with thanks to http://cleverness.org/2010/08/08/add-user-types-to-wordpress-and-buddypress/ found another starting point:

    Put this in you BuddyPress theme /registration/register.php file:

    `

    User Type A
    User Type B
    User Type C

    `

    Put the following code in your theme’s functions.php:

    `<?php
    /* Add sign-up field to BuddyPress sign-up array*/
    function bp_custom_user_signup_field( $usermeta ) {
    $usermeta = $_POST;

    return $usermeta;
    }
    add_filter( ‘bp_signup_usermeta’, ‘bp_custom_user_signup_field’ );

    /* Add field_name from sign-up to usermeta on activation */
    function bp_user_activate_field( $signup ) {

    update_usermeta( $signup, ‘signup_type’, $signup );

    return $signup;
    }
    add_filter( ‘bp_core_activate_account’, ‘bp_user_activate_field’ );

    function synchro_wp_usermeta($user_id, $password, $meta) {
    global $bp, $wpdb;

    $type = $meta[signup_type];

    update_usermeta( $user_id, ‘signup_type’, $type );

    }
    add_action( ‘wpmu_activate_user’, ‘synchro_wp_usermeta’, 10, 3);
    `

    This should create selection of account types on the signup page.
    If anyone knows how to update profile-loop.php, so that every account type would have different profile group, please share your opinion.

    thanks.

    @noizeburger

    Participant

    Any news on this? A big step forward, but as Janis said, we need a way to update profile-loop.php….

    Thanks

    @noizeburger

    Participant

    @janismo

    Participant

    hi
    @noizeburger

    haven’t time to check full code yet, but Cindy (author) replied that everything works fine for her. She is really open for help, contact her with any further questions you have.

Viewing 21 replies - 1 through 21 (of 21 total)
  • The topic ‘Can you run multiple profile loops in single/profile-loop.php ?’ is closed to new replies.
Skip to toolbar