simple better way

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lerizzle
Forum Newbie
Posts: 2
Joined: Fri Nov 12, 2010 11:15 am

simple better way

Post by lerizzle »

Is there a better way to write this? Like in 1 line without the if?

$link_text = get_post_meta($post->ID, 'excerpt_link', true);
if(!$link_text)
$link_text = 'Continue Reading';
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: simple better way

Post by Celauran »

You could use a ternary operator:

Code: Select all

$link_text = get_post_meta($post->ID, 'excerpt_link', true) ? get_post_meta($post->ID, 'excerpt_link', true) : 'Continue Reading';
lerizzle
Forum Newbie
Posts: 2
Joined: Fri Nov 12, 2010 11:15 am

Re: simple better way

Post by lerizzle »

Thanks. thats what I was looking for.
Post Reply