Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查三值运算符中是否为空_Php_Wordpress - Fatal编程技术网

Php 检查三值运算符中是否为空

Php 检查三值运算符中是否为空,php,wordpress,Php,Wordpress,我有一个turnery操作符,检查Wordpress帖子类型是否为链接格式。如果是,则输出自定义字段,如果不是,则输出永久链接 我如何检查自定义字段是否为空?因此,如果为空,则输出永久链接,如果不是,则输出自定义字段 这就是我目前所拥有的 <h3><a href="<?php get_post_format() == 'link' ? the_field("external_link") : the_permalink(); ?>" rel="bookmark" t

我有一个turnery操作符,检查Wordpress帖子类型是否为链接格式。如果是,则输出自定义字段,如果不是,则输出永久链接

我如何检查自定义字段是否为空?因此,如果为空,则输出永久链接,如果不是,则输出自定义字段

这就是我目前所拥有的

<h3><a href="<?php get_post_format() == 'link' ? the_field("external_link") : the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

我在想一些类似的事情,但似乎不起作用

<h3><a href="<?php get_post_format() == 'link' && the_field("external_link") !="" ? the_field("external_link") : the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

如果值正常,则此操作应有效:

<?php (get_post_format() == 'link' && the_field("external_link")) ? the_field("external_link") : the_permalink(); ?>

2种方法:-

1.在条件周围添加
()

<h3><a href="<?php (get_post_format() == 'link' && the_field("external_link") !="") ? the_field("external_link") : the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

2.先检查条件并将其分配给变量,然后再使用它

<?php $link = (get_post_format() == 'link' && the_field("external_link") !="") ? the_field("external_link") : the_permalink();
<h3><a href="<?php echo $link; ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
在条件周围添加
()
并检查:-
(获取帖子格式()='link'&字段(“外部链接”)!=“”