【发布时间】:2020-12-21 22:23:16
【问题描述】:
我得到了一个 ACF Reaper 字段,其中包含我试图显示的几行。但是,我只想要显示行,如果它选中了一个复选框(复选框是转发器中的一个子字段)。我试图通过使用 if in_array 来实现这一点,如“条件逻辑”下的ACF documentation 中所述:
if( in_array( "bestyrelsevalg", get_sub_field( 'bestyrelse' ) ) )
我以 WordPress 简码输出结果。现在,我的代码有点工作,只是它显示了转发器字段中的所有结果(也包括那些未选中的结果)。我错过了什么??
我的代码:
function investor_bestyrelse_shortcode() {
$rows = get_field('budgetter_og_nyhedsbreve');
if( $rows ) {
echo '<ul class="slides">';
foreach( $rows as $row ) {
if( in_array( "bestyrelsevalg", get_sub_field( 'bestyrelse' ) ) ) {
$image = $row['upload_dokument'];
echo '<li>';
echo get_field( 'upload_dokument' );
echo '</li>';
}
}
echo '</ul>';
}
}
add_shortcode( 'investor_bestyrelse', 'investor_bestyrelse_shortcode' );
【问题讨论】:
标签: php wordpress if-statement checkbox advanced-custom-fields