Php 如何在Wordpress中编写get\U post\U meta的if语句
我正在尝试更正get_post_meta的if语句。我想显示的信息,如果有什么东西,如果没有,不显示任何东西。这里有一个例子,我正在工作,没有运气Php 如何在Wordpress中编写get\U post\U meta的if语句,php,wordpress,if-statement,Php,Wordpress,If Statement,我正在尝试更正get_post_meta的if语句。我想显示的信息,如果有什么东西,如果没有,不显示任何东西。这里有一个例子,我正在工作,没有运气 if(get_post_meta()); echo '<a href="'.get_post_meta($post->ID, 'text', true).'">'; endif; if(get_post_meta());回声';endif; 感谢您的帮助。谢谢。您在语法上犯了一个错误。使用 if($condition): sta
if(get_post_meta()); echo '<a href="'.get_post_meta($post->ID, 'text', true).'">'; endif;
if(get_post_meta());回声';endif;
感谢您的帮助。谢谢。您在语法上犯了一个错误。使用
if($condition): statements; endif;
^
而不是
if($condition); statements; endif;
^
所以你的代码是
if(get_post_meta()):
echo '<a href="'.get_post_meta($post->ID, 'text', true).'">';
endif;
非常感谢。那很好用。我确实知道另一种方式,我认为这样做会更干净。谢谢你的帮助!是的,这是唯一的优势,我会告诉你,它看起来更干净,特别是当它与HTML代码混合时。另外,请记住get_post_meta()的$post_id参数是必需的,因此不带参数调用它不会有多大好处。我建议只调用它一次,并存储返回值,以便与if语句和后续输出一起使用。
if($conition) {
// statements
// .....
}
else {
// otherweise
}