Need to check if bp_profile_field_data() has data
-
I need to check for data in the bp_profile_field_data()
If it has been filled in by the member then I want to show it in the member-header.php
But if it’s empty I don’t want it to show. I will be adding CSS styling to this to show an Icon in place of the text link.
So how can I add an If statement to this to check for the existence of data?
-
+1, have you found anything yet?
Have you tried calling bp_get_profile_field_data and testing against NULL / empty string?
Here’s its definition:
function bp_get_profile_field_data( $args = ” ) {
$defaults = array(
‘field’ => false, // Field name or ID.
‘user_id’ => $bp->displayed_user->id
);..
}Most of the template tags have a “get” version that doesn’t echo the result.
@rogercoathup where do I have to add this and what do I need to change?
thanks you
in your child theme, wherever you want to hide fields that have no data, you can put a simple if statement, something like:
if (bp_get_profile_field_data(‘field=your-field-id’) === “”) :
// don’t display code
else:
// display code
endif;Which file to edit, all depends where it is you are wanting to display / hide the profile field. The most likely file for displaying profile fields is profile-loop.php in members/single/profile, but that already skips blank fields (using a call to bp_field_has_data(); that function has to be used inside the profile field loop).
@rogercoathup thanks but my php isnt really so good this one dont work:
if (bp_get_profile_field_data(‘field=your-field-id’) === “”) :
div style xy xy xy xy (the part which should be shown when its filled outelse:
you have to fill it out messageendif;
I’m not really sure what you are trying to do with your code. Whereabouts are you trying to hide fields with no data? In the default theme profile-loop.php, fields without values are already not displayed.
As for quick fixes: You’ll need to replace ‘your-field-id’ with a variable that’s got the field id in it. You’ll also need to write valid PHP e.g. closing the PHP code before beginning your html. I’d steer clear of inline style definitions as well; the default BuddyPress theme comes with a comprehensive set of CSS files, and you’d be better augmenting these with style definitions.
Unfortunately, this forum isn’t really the appropriate place for PHP coding tutorials – You might be better reading up on PHP before attempting to modify the theme templates in any depth.
as I said I’ve got something like
div stlye …
img src=image.png…
bp_profile_field_data( ‘field=About Me’ );
end divand I want only to show div style if the field about me is filled out otherwise I get a picture and the div style with an empty place.
Are you using the default theme, or something similar? Are you trying to do this in the profile-loop.php file inside the profile loop? Is it only the About Me field you want to replace?
if so, you need to edit your profile loop with something like this (note: the default template files use tables for the profile display):
Making use of the bp_get_the_profile_field_name() to check you are only applying your image to the correct field.
And use the CSS files to style the table cells appropriately.
@rogercoathup yeah I’m using the default theme and I just tried it I get this error:
Parse error: syntax error, unexpected T_IF, expecting ‘:’
My code snippet is indicative, and shows you the basics of what you need to do… You can’t just insert it verbatim. Did you edit my code snippet, and add your image code as needed? Did you place it in the correct place in profile-loop.php?
It may be because I used “else if” with colons, which apparently is invalid – try combing “else if” into one word “elseif”.
Generally, for an unexpected T_IF, you just need to go in and check your PHP is balanced / syntactically correct, but in this case it might well be the “else if” separation.
If you still have a problem… post your code (via pastebin). It’s impossible to know from the information you’ve given where you’ve inserted my snippet, what’ve you added, and consequently what’s causing the unexpected T_IF.
okay @rogercoathup now it works but only for the field about me…
I’ve got another field and tried it it doesnt work??
my about me field is an textarea I’ve created something like it it didnt worked@tubruk : As I said in my previous post… you’ll have to post your code (use pastebin.com) so that we can see where your problem might be.
okay sorry:
Is your field definitely called “skills” – no spaces, same capitalisation?
Things to try (one at a time):
1. use == instead of ===
2. use strcmp() to compare the strings instead of ===
3. use the field id function instead of the field name functionGood luck.
p.s. I’d change your ‘else if’ to ‘elseif’ as well
- The topic ‘Need to check if bp_profile_field_data() has data’ is closed to new replies.