So I realised looking at this page:
Profile Fields Loop
That I have no idea how it’s getting its data.
There’s no arrays or variables being set. There’s these functions:
bp_has_profile()
bp_profile_groups()
and so on.
But none of these do any assignments of variables or results.
I suspect my PHP/programming knowledge is way out of date. Because there’s something sophisticated or hidden going on here with those functions that I just don’t understand.
As usual glad to be pointed at background reading…
That’s because these are loop functions, designed to provide data from the current profile in the loop.
Which profile group are you looking to get the data for, and which field?
I’m lookig to get the xprofile data out. And also poke it in.
I’m afraid that you might have to get more basic than what you’ve said.
What’s a loop function and how does it pass data from one function to another. I interpret a loop as a “for each” or a “while” or similar that loops through an array or whatever.
Are these objects or classes that are doing something I don’t understand?
Glad to be told that I need to read up on xxxx or yyyy.
At the moment it just looks like black magic.
When not using a BP profile loop, try using xprofile_get_field_data.
Loop functions are a pretty basic feature of WordPress, in WP 101 terms it’s basically lesson 2 – how the posts page displays a list of all posts. It does this by having a loop – using a function to pull in all posts (or in bp members or groups) then using a while loop to iterate through all those posts, members groups etc, depending on the context.
So a bp Loop looks something like this:
If has_members:
While has_members:
print out the info you want
End while
Else
// there were no members
Sweet.
The problem I have is that I’m used to using variables in loops. $variable etc.
But the loop page is only using functions (AFAIK).
I assume that’s a standard PHP capability, but I don’t know how to search for what that’s called to read up on it…
I also was ignorant of the alternative syntax for control structures. I’ve read up on it and wanted to check that:
while ( bp_profile_groups() ) : bp_the_profile_group();
endwhile;
was 100% equivalent to:
while ( bp_profile_groups() ){
bp_the_profile_group();
}
I’ve actually tried putting that exact code, in both syntaxes, into my test page.
And it kind of silently fails. It brings up bits of the page, but then stops. And I can’t even pull up the source or the Chrome Developer window.
How do the functions in the loop get their parameters to return values?
Is everything being set globally? If so, then how do we know which functions have to be caleld first to set up the variables?
Thanks for all your help. 🙂
I’ve tried xprofile_get_field_data using this code:
$args = array(
'field' => 'Nickname'
);
$result = xprofile_get_field_data($args);
print ("<br><br>");
print ("XProfileData");
print ("<br>");
var_dump($result);
But all it does is return “FALSE”
That xprofile field definately exists
Thanks to someone on WPMU dev, I tried this:
$profile_data = BP_XProfile_ProfileData::get_all_for_user( 1 );
echo '<pre>';
print_r($profile_data);
echo '</pre>';
This returns the Profile fields…