如果该字段为空,请勿在列表中显示自定义字段

问题描述 投票:1回答:1

早上好。我已经设置了自定义字段修改功能列表.php。一切都有效,但我想隐藏一个场是空的。我已经阅读了很多关于它的帖子,但我无法摆脱我的问题。

这里是我的PHP代码:

   // Show advanced custom fields in product detail page
add_action( 'woocommerce_single_product_summary', "ACF_product_content", 26 );
 

function ACF_product_content(){

 
  if (function_exists('the_field')){
    echo '<b>MATERIA: </b>';
    the_field('materia'); 
echo "<br />";
    echo '<b>FECHA DE EDICIÓN: </b>';
    the_field('fecha_de_edicion');
echo "<br />";
echo '<b>LUGAR DE EDICIÓN: </b>';
    the_field('lugar_de_edicion');
echo "<br />";
echo '<b>ISBN: </b>';
    the_field('isbn');
echo "<br />";
echo '<b>ISBN DIGITAL: </b>';
    the_field('isbn_digital');
echo "<br />";
echo '<b>ENCUADERNACIÓN: </b>';
    the_field('encuadernacion');
echo "<br />";
echo '<b>INTERIOR: </b>';
    the_field('interior');
echo "<br />";
echo '<b>MEDIDAS: </b>';
    the_field('medidas');
echo "<br />";
echo '<b>NÚMERO DE PÁGINAS: </b>';
    the_field('numero_de_paginas');
echo "<br />";
echo '<b>IDIOMA: </b>';
    the_field('idioma');
echo "<br />";
echo '<b>CÓDIGOS IBIC: </b>';
    the_field('ibic');
  }
  
} 

如果它是空的,任何人都可以帮我隐藏其中一个字段?谢谢

php wordpress field custom-fields
1个回答
1
投票

改为使用get_field,然后使用条件检查该字段是否为空,然后echo该字段。

例:

$materia = get_field('materia');
if($materia) {
    echo '<b>MATERIA: </b>';
    echo $materia;
}
© www.soinside.com 2019 - 2024. All rights reserved.