Php 循环以显示ACF组中的所有字段/行

Php 循环以显示ACF组中的所有字段/行,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我想使用下面的代码显示其中一个ACF组中的所有行。不幸的是,什么也没有出现。我可以请求不正确的帮助吗 <div class="product-atributes"> <div class="atributes-form"> <?php for ($i=1; $i<3; $i++) { if (have_rows($atrybut.$i))

我想使用下面的代码显示其中一个ACF组中的所有行。不幸的是,什么也没有出现。我可以请求不正确的帮助吗

<div class="product-atributes">
    
        <div class="atributes-form">
        <?php 
        for ($i=1; $i<3; $i++) {
            if (have_rows($atrybut.$i)) {
                while (have_rows('atrybut_'.$i)) {
                    the_row();
        // vars
        $quantity = get_sub_field('quantity');
        $ean = get_sub_field('ean');
        $linkap = get_sub_field('linkap');
        ?>
            <div class="flex-body">
                <div class="flex-column">
                    <div>Quantity: <?php echo $quantity ?></div>
                    <div>EAN: <?php echo $ean ?></div>
                </div>
                <div class="flex-row">
                    <div><span><a href="<?php echo $linkap ?>" target="_blank" rel="nofollow">BUY</a></span></div>
                </div>
            </div>
            <?php } } } 
            ?>
        </div>
    </div>

数量:
EAN:

看起来您在这里输入了一个错误:

  if (have_rows($atrybut.$i)) {
                while (have_rows('atrybut_'.$i)) {
哪个是正确的字段名
$atrybut.$i
'atrybut.$i

您还缺少一些结尾

更新:添加条件显示:

...

$quantity = get_sub_field('quantity');
$ean = get_sub_field('ean');
$linkap = get_sub_field('linkap');

// may need to tweak this logic based on what the
// values might/could be but this should get you going
$has_all_acf_fields = $quantity && $ean && $linkap;

if ($has_all_acf_fields) {
?>
    <div class="flex-body">
        <div class="flex-column">
            <div>Quantity: <?php echo $quantity; ?></div>
            <div>EAN: <?php echo $ean; ?></div>
        </div>
        <div class="flex-row">
            <div><span><a href="<?php echo $linkap; ?>" target="_blank" rel="nofollow">BUY</a></span></div>
        </div>
    </div>
<?php 
}

...
。。。
$quantity=获取子字段(“数量”);
$ean=获取子字段(“ean”);
$linkap=获取子字段(“linkap”);
//可能需要根据
//值可能是/可能是,但这应该会让您继续
$has_all_acf_字段=$quantity&&$ean&&$linkap;
如果($has\u all\u acf\u字段){
?>
数量:
EAN:

看起来您在这里输入了一个错误:

  if (have_rows($atrybut.$i)) {
                while (have_rows('atrybut_'.$i)) {
哪个是正确的字段名
$atrybut.$i
'atrybut.$i

您还缺少一些结尾

更新:添加条件显示:

...

$quantity = get_sub_field('quantity');
$ean = get_sub_field('ean');
$linkap = get_sub_field('linkap');

// may need to tweak this logic based on what the
// values might/could be but this should get you going
$has_all_acf_fields = $quantity && $ean && $linkap;

if ($has_all_acf_fields) {
?>
    <div class="flex-body">
        <div class="flex-column">
            <div>Quantity: <?php echo $quantity; ?></div>
            <div>EAN: <?php echo $ean; ?></div>
        </div>
        <div class="flex-row">
            <div><span><a href="<?php echo $linkap; ?>" target="_blank" rel="nofollow">BUY</a></span></div>
        </div>
    </div>
<?php 
}

...
。。。
$quantity=获取子字段(“数量”);
$ean=获取子字段(“ean”);
$linkap=获取子字段(“linkap”);
//可能需要根据
//值可能是/可能是,但这应该会让您继续
$has_all_acf_字段=$quantity&&$ean&&$linkap;
如果($has\u all\u acf\u字段){
?>
数量:
EAN:

如果要获取
ACF Group
字段,则必须首先获取
Group\u字段\u name
。如下所示

<?php
    $main_group_field = get_field('GROUP-FIELD-NAME');

    // Group's field returs array. So can fetch subfields like this.
    $quantity = $main_group_field['quantity'];
    $ean = $main_group_field['ean'];
    $linkap = $main_group_field['linkap'];
?>

如果要获取
ACF组
字段,则必须首先获取
Group\u字段名称
。如下所示

<?php
    $main_group_field = get_field('GROUP-FIELD-NAME');

    // Group's field returs array. So can fetch subfields like this.
    $quantity = $main_group_field['quantity'];
    $ean = $main_group_field['ean'];
    $linkap = $main_group_field['linkap'];
?>

谢谢你的评论。在我的情况下,我有一个组有单独的字段…所以我只有一个字段名错误。谢谢你的评论。在我的情况下,我有一个组有单独的字段…所以我只有一个字段名错误。你是对的!我有一个不正确的字段名…你能告诉我如何添加一个条件来显示c吗仅当字段已填充时才显示我的div的内容?更新答案以包含条件显示示例。你是对的!我的字段名称不正确…请告诉我如何添加条件以仅当字段已填充时显示我的div的内容?更新答案以包含条件显示示例。