admin管理员组文章数量:1289832
How to display any text/content if all buddypress user profile fields are not filled?
Here is my code which retrieves field data if the field is filled by the user:
$fields = array('Field 1', 'Field 2', 'Field 3', 'Field 4', 'Field 5');
foreach ( $fields as $field) {
$data = xprofile_get_field_data($field);
if ($data) {
echo '<div class="">'. $field .' - '. $data .'</div>';
}
}
// How to display here information if all 5 fields are not filled by user?
How to display any text/content if all buddypress user profile fields are not filled?
Here is my code which retrieves field data if the field is filled by the user:
$fields = array('Field 1', 'Field 2', 'Field 3', 'Field 4', 'Field 5');
foreach ( $fields as $field) {
$data = xprofile_get_field_data($field);
if ($data) {
echo '<div class="">'. $field .' - '. $data .'</div>';
}
}
// How to display here information if all 5 fields are not filled by user?
Share
Improve this question
asked Jul 19, 2021 at 12:11
AvigoAvigo
377 bronze badges
1 Answer
Reset to default 1You could use, what i call flag (don't remember the profitional term but im sure there is one).
The idea is to create a variable that has a boolean value, depends on the situation, for our example it will be false.
So basicaly from the very start we assume that all fields have no values and every thing is ok, in the foreach we will do the check if the field actualy has a value, if it has, we will set our flag to true.
Now we know that if our flag was false, we can display what we want, but if its true we don't display.
The code will be like this
$fields = array('Field 1', 'Field 2', 'Field 3', 'Field 4', 'Field 5');
$flag = false;
foreach ( $fields as $field) {
$data = xprofile_get_field_data($field);
if ($data) {
echo '<div class="">'. $field .' - '. $data .'</div>';
$flag = true;
}
}
if (!$flag) {
// display here information if all 5 fields are not filled by user
}
本文标签: usersHow to display text if profile fields are not filled
版权声明:本文标题:users - How to display text if profile fields are not filled? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741433342a2378490.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论