Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I check an array of $curauth user data? I need to check to see if one or more $curauth fields have data, and if so, print some html. This throws an array error:

    <?php if ( !empty( array ( $curauth->facebook, $curauth->linkedin, $curauth->twitter)))
{ echo 'echo me if any $curauth info exists for the fields in the array above'; } ?>

Update - this works:

<?php  if (!empty ($curauth->facebook) || ($curauth->linkedin) || ($curauth->twitter))
{ echo 'echo me if any $curauth info exists for the fields in the array above';  }  ?>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Try

<?php 
if ( !empty( array ( $curauth->facebook ) ) || 
     !empty ( array ( $curauth->linkedin ) ) || 
     !empty( array( $curauth->twitter ) ) )
{ 
    echo 'echo me if any $curauth info exists'; 
} 
?>

Note: This can be all on fewer lines, I've just put in additional line-breaks to make it all fit to avoid a horizontal scrollbar.


Update:
Reading up on Author Templates made me realise that once you've set the $curauth variable, e.g.

$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));

you should be able to use this instead:

<?php 
if ( !empty ( $curauth->facebook ) || 
     !empty ( $curauth->linkedin ) || 
     !empty ( $curauth->twitter ) )
{ 
    echo 'echo me if any $curauth info exists'; 
} 
?>
share|improve this answer
    
Thanks, that works. I already call the $curauth variable. I wasn't formatting the array the right way. But the code can be simplified a little as noted in my update to my question. –  songdogtech Dec 24 '11 at 17:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.