具有默认内容的条件逻辑和高级自定义字段

时间:2019-04-09 21:28:52

标签: php wordpress if-statement conditional advanced-custom-fields

我正在使用高级自定义字段来显示URL中的内容。这些字段中包含默认内容(我提到的url)。当选择纽约时,我在具有ID(“ nearestCity”)的单选按钮上使用条件逻辑,该按钮显示包含纽约URL的字段。问题在于,由于“字段ID”不同,因此内容不会显示,因此我想编写一个条件语句,以在选择“纽约”时重新定义变量。

我尝试使用相同的ID并编写IF语句,但两者都只是破坏了页面

<?php
$propertiesCity = get_post_meta($post->ID, 'propertiescityname', true);
$msa = get_post_meta($post->ID, 'propertiesmsa', true);
?>
<?php 
/*code for adding nearest new york city*/

$newYorkSelect = get_post_meta($post->ID, 'nearest_city', true);

if ($newYorkSelect == "new york") { ?>

<? 
    $propertiesCity = get_post_meta($post->ID, 'propertiescityname-new-york', true);
    $msa = get_post_meta($post->ID, 'propertiesmsa-new-york', true); 
?>

<?php 

} else { 
// do nothing; 
}

?>

0 个答案:

没有答案
相关问题