Php 如果存在自定义字段值,则显示,如果不存在,则显示另一个自定义字段值

Php 如果存在自定义字段值,则显示,如果不存在,则显示另一个自定义字段值,php,wordpress,if-statement,custom-fields,Php,Wordpress,If Statement,Custom Fields,我有一个Wordpress管理的网站,我已经建立了它,一切都像我希望的那样工作,我对结果很满意,因为这是我第一个完全建立的Wordpress网站 我被本周初提出的一个请求卡住了 我们有一个物业出售页面(http://www.urbanvision.org.uk/services/property-services/properties-for-sale/)此页面上的项目链接到计划和财产详细信息的PDF下载。但是,我们现在有一些属性需要添加到外部链接,而不是PDF链接 我的问题是页面模板依赖于插件

我有一个Wordpress管理的网站,我已经建立了它,一切都像我希望的那样工作,我对结果很满意,因为这是我第一个完全建立的Wordpress网站

我被本周初提出的一个请求卡住了

我们有一个物业出售页面(http://www.urbanvision.org.uk/services/property-services/properties-for-sale/)此页面上的项目链接到计划和财产详细信息的PDF下载。但是,我们现在有一些属性需要添加到外部链接,而不是PDF链接

我的问题是页面模板依赖于插件高级自定义字段管理的自定义字段,上载PDF的字段是一个文件上载字段,它将获取PDF,而不是指向其他页面或站点的URL

我曾尝试将自定义字段切换到URL而不是上载屏幕,但对此并不感兴趣,原因有二:1)我会返回其他属性并将URL复制到已更改的字段中;2)同事更新URL会变得有点困难

我还尝试引入一个单独的a字段,并确定应该拉入哪个自定义字段:

如果属性_details中存在PDF文件,请将URL拉入PDF。 如果URL存在于属性\u详细信息\u URL中,请拉入输入的URL

每个帖子有两个部分需要链接到更多详细信息(PDF或外部URL)。它们是缩略图和查看详细信息链接

我以前的代码(仅链接到PDF):

<?php
$featuredPosts = new WP_Query();
$featuredPosts->query('showposts=20&cat=13');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>

<div class="literaturedescription">
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>">
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a>
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span>

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br />
    <?php $featuredPosts = new WP_Query(); 
$featuredPosts->query('showposts=20&cat=12');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>

<div class="literaturedescription">
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>">
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a>
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span>


<?php if(get_field('property_details_url')){ ?>

<br /><a href="<?php the_field('property_details_url'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br />

<?php } else { ?>

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br />

<?php } ?>




我已将其更改为的代码(仍然无法使其工作):

<?php
$featuredPosts = new WP_Query();
$featuredPosts->query('showposts=20&cat=13');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>

<div class="literaturedescription">
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>">
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a>
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span>

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br />
    <?php $featuredPosts = new WP_Query(); 
$featuredPosts->query('showposts=20&cat=12');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>

<div class="literaturedescription">
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>">
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a>
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span>


<?php if(get_field('property_details_url')){ ?>

<br /><a href="<?php the_field('property_details_url'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br />

<?php } else { ?>

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br />

<?php } ?>






我还查看了直接从Wordpress正在使用的MySQL数据库中提取数据的情况,但确实很难让页面显示无误


一如既往,我们非常感谢您的帮助。

您的方法是正确的,但要做的是将customfield指定给变量

即:






希望检查应该可以确定属性\u details\u url除了没有之外还有其他内容,它将显示链接,如果没有,它将显示另一段代码

马蒂