Forum Moderators: coopster

Message Too Old, No Replies

PHP if isset problem

         

almo136

4:13 pm on Aug 7, 2009 (gmt 0)

10+ Year Member



Hi,

In Wordpress this will output the authors aim id from their profile
the_author_meta('aim');

I would like to output certain text only if the user has set a aim id in their profile. I tried this but it always outputs the text even if the aim id isn't set:

<?php
$thereisaim = get_the_author_meta('aim');

if (isset($thereisaim)) {
echo 'hello world';
}
?>

How can I get this to work?

Thanks.

jatar_k

5:19 pm on Aug 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that function returns something when there is no aim set, so isset will always return true. You just need to figure out what it returns when they haven't set one.

almo136

5:47 pm on Aug 7, 2009 (gmt 0)

10+ Year Member



How could I find out what gets returned when it isn't set?

I tried

<?php the_author_meta('aim'); ?>

When there was no value set for aim and it didn't return anything.

bkeep

8:20 pm on Aug 7, 2009 (gmt 0)

10+ Year Member



you could try empty instead


$thereisaim = get_the_author_meta('aim');

if (!empty($thereisaim)) {
echo 'hello world';
}

almo136

8:41 pm on Aug 7, 2009 (gmt 0)

10+ Year Member



that did the trick. Thanks.