获取存储在数据库中的转发器子字段的所有值

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

[目前,我正在努力使用ACF(高级自定义字段)中继器字段。第一个问题是此字段类型的一般体系结构-它没有存储在数据库中的单个位置,而是相乘(例如,如果我的中继器字段名称称为workshops_grouping,而子字段称为data,那么将存在workshops_grouping_1_data,workshops_grouping_2_data等)。

因此,我想比ACF(:)更加聪明,并且我认为,如果我将使用以下代码从CPT中获取所有帖子ID,那么它将更加容易。这是代码:

<?php
    $other_page = get_posts( array(
        'posts_per_page' => -1,
        'fields' => 'ids',
        'post_type' => 'workshops',
        'post_status' => 'publish',
    ) );

if( have_rows('workshops_grouping', $other_page) ): ?>

    <select id="no1">

    <?php while( have_rows('workshops_grouping', $other_page) ): the_row(); ?>

        <option value="<?php the_sub_field('data'); ?>"><?php the_sub_field('data'); ?></option>

    <?php endwhile; ?>

    </select>

    <select id="no2">

    <?php while( have_rows('workshops_grouping', $other_page) ): the_row(); ?>

        <option value="<?php the_sub_field('company'); ?>"><?php the_sub_field('company'); ?></option>

    <?php endwhile; ?>

    </select>

<?php endif; ?>

但是嘿,你猜怎么着-它根本不起作用。含义=它什么也不显示。我在ACF的官方社区委员会上也经历过几次类似的帖子。到目前为止没有成功。甚至可行吗?

wordpress while-loop advanced-custom-fields repeater
1个回答
0
投票

根据ACF文档,您必须在have_rows函数内部传递一个ID。https://www.advancedcustomfields.com/resources/have_rows/

© www.soinside.com 2019 - 2024. All rights reserved.