Reputation: 2157
I'm trying to right an if statement for get_post_meta. I want to display the info if something is there, if there is nothing, don't display anything. Here is an example I am working with, with no luck.
if(get_post_meta()); echo '<a href="'.get_post_meta($post->ID, 'text', true).'">'; endif;
Any help is appreciated. Thanks.
Upvotes: 0
Views: 1127
Reputation: 6968
You've made an error in the syntax. Use
if($condition): statements; endif;
^
instead of
if($condition); statements; endif;
^
So your code would be
if(get_post_meta()):
echo '<a href="'.get_post_meta($post->ID, 'text', true).'">';
endif;
That's the alternative syntax for control structures.
You can always use the standard one
if($conition) {
// statements
// .....
}
else {
// otherweise
}
Upvotes: 1