WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Current User info hiding a row (3 posts)

  1. qgibbs1
    Member
    Posted 1 year ago #

    I have a table that is showing some of the current user info for someone who is logged in. The problem is, if the info is not there or the field is blank I want the entire row not to be shown. Such as Middle Name. If the middle name is not there or is empty I want it to be show like this.

    First Name: Blah
    Last Name: Blahas

    and not

    First Name: Blah
    Middle Name:
    Last Name: Blahas

    The code I have is

    <?php global $current_user;  get_currentuserinfo(); echo 'Relationship to Employee:' . $current_user->dep1_relationship . "\n";?><br>
    <?php global $current_user;  get_currentuserinfo(); echo 'First Name:' . $current_user->dep1_firstname . "\n";?>
    <?php global $current_user;  get_currentuserinfo(); echo 'Middle Name:' . $current_user->dep1_middlename . "\n";?>
    <?php global $current_user;  get_currentuserinfo(); echo 'Last Name:' . $current_user->dep1_lastname . "\n";?><br>
    <?php global $current_user;  get_currentuserinfo(); echo 'SSN:' . $current_user->dep1_social . "\n";?><br>
    <?php global $current_user;  get_currentuserinfo(); echo 'Date of Birth:' . $current_user->dep1_dob . "\n";?><br>
    <?php global $current_user;  get_currentuserinfo(); echo 'Gender:' . $current_user->dep1_gender . "\n";?><br>
    <?php global $current_user;  get_currentuserinfo(); echo 'Student:' . $current_user->dep1_student . "\n";?><br>
    <?php global $current_user;  get_currentuserinfo(); echo 'Add of Cancel:' . $current_user->dep1_addorcancelcoverage . "\n";?><br>

    Thank you for your help.

  2. codingpet
    Member
    Posted 1 year ago #

    <?php global $current_user; get_currentuserinfo(); if( !empty($current_user->dep1_middlename) ){ echo 'Middle Name:' . $current_user->dep1_middlename . "\n"; } ?>

    Something like this may solve your issue. Also, I don't think you need to write "global $current_user; get_currentuserinfo();" for so many times. Just write it once at the start the your codes.

  3. qgibbs1
    Member
    Posted 1 year ago #

    Thank you very much! It worked like a charm. You are awesome!

Topic Closed

This topic has been closed to new replies.

About this Topic