Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_get_field_data no longer working


  • psfk
    Participant

    @psfk

    I had been able to hack the directories page to display member data with

    <?php echo bp_get_field_data( ‘One Line Summary’, $user->user_id ) ?>

    But the RC2 version does not recognize the code anymore.

    Is there an alternative?

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

  • Burt Adsit
    Participant

    @burtadsit

    If you upgrade your theme to the version that is in RC2 you can take advantage of the new member template functions that are available to you. The directories now have their own little templates located in /buddypress-member/directories/<directorytype>/<directorytype>-loop.php file.

    Then all the template tags you find in /bp-core/bp-core-templatetags.php are available to you. That particular function you were using doesn’t exist anymore. The underlying call still works which is:

    BP_XProfile_ProfileData::get_value_byfieldname( $field, $user_id );

    so

    BP_XProfile_ProfileData::get_value_byfieldname( ‘One Line Summary’, $user->user_id );

    Should work. I encourage you to look at the new directory code and templates.

    Try to use the passthrough functions:

    xprofile_get_field_data( $field_name, $user_id );
    xprofile_set_field_data( $field_name, $user_id, $value );


    Burt Adsit
    Participant

    @burtadsit

    Or you could use those handy passthrough functions that I wasn’t aware of.


    psfk
    Participant

    @psfk

    Hmmm… while it doesn\’t give me an error, this does not return any result:

    <?php echo xprofile_get_field_data( \’city\’, $user->user_id ) ?>

    See – http://purplelist.com/members


    Burt Adsit
    Participant

    @burtadsit

    I would check that ‘city’ is the actual field name and not ‘City’ and that $user is a global var that is valid where you are trying to use it.


    psfk
    Participant

    @psfk

    Thanks Burtadsit. So I’ve tried every option I can think of and can’t get it to display. Andy?

    Assuming you’ve got the field name correct as per Burtadsit’s suggestion, check what you are passing as the second argument. It needs to have an integer user id – i.e. are you sure that’s $user->user_id and not $user->id or similar?


    psfk
    Participant

    @psfk

    Now I’m just getting 1s and 0s in the results with

    <?php echo xprofile_get_field_data( ‘Availability To Be Hired As An Expert’, $user->user_id) ?>

    Something’s being evaluated as a boolean.

    Where exactly are you putting that code? I don’t know how much/any PHP you know I’m afraid, so it’s possible I might be teaching you to suck eggs, but the $user variable might not exist (let alone what type of object it is).


    psfk
    Participant

    @psfk

    unlikely that you are teaching me to suck eggs. So in members-loop.php I am changing the code to say:

    <div class="item">
    <div class="item-title">
    <a href="<?php bp_the_site_member_link() ?>"><?php bp_the_site_member_name() ?></a></div>
    <div class=\\\\\\\"item-meta\\\\\\\">
    <p><b>Availability:</b> <?php echo xprofile_get_field_data( 'Availability To Be Hired As An Expert', $user->user_id ) ?>
    </p> </div>

    <?php do_action( 'bp_core_directory_members_content' ) ?>
    </div>


    Burt Adsit
    Participant

    @burtadsit

    It’s not just you psfk. I tried this out in members-loop.php with BP_XProfile_ProfileData::get_value_byfieldname( $field, $user_id ) and it just returns false for me too. I left out the user id param because it isn’t needed. The current user is used instead. Just wanted something. Got nothing.


    Burt Adsit
    Participant

    @burtadsit

    The reason you are getting nothing is that $user is not a global var in that template. I was getting nothing because of a bug. Specify the user var like this:

    <?php
    global $site_members_template;
    xprofile_get_field_data(\"City\",$site_members_template->member->id);
    ?>

    That is the current template user id. There is no template tag to just get the current template loop user id yet.


    Burt Adsit
    Participant

    @burtadsit

    I was getting nothing because the class methods are not designed to be called from a template loop. Not using a user id defaults to the current user id viewing the member theme page and that’s not valid for anything inside a template loop.

    Anyway I posted a ticket with a fn to get at the current loop user id. https://trac.buddypress.org/ticket/684

    just use:

    bp_loggedin_user_id()
    bp_displayed_user_id()


    psfk
    Participant

    @psfk

    OK, I went and installed the latest patch – now I am getting numbers that look like they must correspond to each member. How do I get bp to publish the data not the integers? This is what I have now:

    <?php echo xprofile_get_field_data( 'One Line Summary', bp_the_site_member_user_id() ); ?>


    psfk
    Participant

    @psfk

    Hmmm… not getting anywhere with this nor any further support. Maybe I should start afresh here:

    https://buddypress.org/forums/topic.php?id=2346&replies=1#post-12800


    stanford
    Participant

    @stanford

    Andy, thanks for the code in the last comment. That works.

    I feel like this should be documented better somewhere. It took me about 20 minutes to find this.

    <?php echo xprofile_get_field_data( $field_name, bp_get_the_site_member_user_id() ); ?>

    Accidentally deleted the previous post.

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘bp_get_field_data no longer working’ is closed to new replies.
Skip to toolbar