bp_get_field_data no longer working
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 );
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 );
Or you could use those handy passthrough functions that I wasn’t aware of.
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 ) ?>
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.
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?
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).
unlikely that you are teaching me to suck eggs. So in members-loop.php I am changing the code to say:
<a href="<?php bp_the_site_member_link() ?>"><?php bp_the_site_member_name() ?></a></div>
<p><b>Availability:</b> <?php echo xprofile_get_field_data( 'Availability To Be Hired As An Expert', $user->user_id ) ?>
<?php do_action( 'bp_core_directory_members_content' ) ?>
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.
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:
That is the current template user id. There is no template tag to just get the current template loop user id yet.
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. http://trac.buddypress.org/ticket/684
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() ); ?>
Hmmm… not getting anywhere with this nor any further support. Maybe I should start afresh here:
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.
You must be logged in to reply to this topic.