ACF 灵活的内容字段

ACF Flexible Content Fields

我设置了一些灵活的内容字段。

其中一个称为 'product-picker',另一个称为 'product-information'。

产品选择器使用 post 对象功能来拉入所选产品。

我可以拉入默认的 wordpress 部分,例如:

<?php the_post_thumbnail(); ?>

但我无法提取 'product-information' 内的值。

这真的可能吗?以下代码摘录:

<?php if( have_rows('content_blocks') ):

    while ( have_rows('content_blocks') ) : the_row();

        if( get_row_layout() == 'product_information' ):

            include("inc/product-information.php");     

        elseif( get_row_layout() == 'products_picker' ):

            include("inc/products-picker.php");

        endif;

    endwhile;

endif; ?>

然后在 'products-picker' 我使用下面的代码:

<?php foreach( $post_objects as $post):  ?>

    <?php setup_postdata($post); ?>

        <div class="product">   

            <?php the_post_thumbnail(); ?>      

            <div class="description">

                    /* Echoing post ID returns correct value */
                    <h1><?php echo $post->ID; ?></h1>

                    /* Does not work */
                    <h1><?php the_sub_field('heading', $post->ID); ?></h1>

                    /* Does not work */
                    <?php the_sub_field('description', $post->ID); ?>

            </div> <!-- .description -->

        </div> <!-- .product-->

<?php endforeach; ?>

<?php wp_reset_postdata(); ?>

我的内容结构可能有误。

也许你不能在灵活内容中调用灵活内容?

但我认为应该可以这样做,因为默认字段如:

the_post_thumbnail(); 

the_title();

工作。

非常感谢您的宝贵时间和帮助。

您必须为每个 post 对象设置灵活的行部分。因此,在您设置 post 数据后,复制您的

if( have_rows('content_blocks') ):
    while ( have_rows('content_blocks') ) : the_row();

每个 post 对象的产品信息字段。

查看 https://www.advancedcustomfields.com/resources/flexible-content/ 和嵌套循环示例。我认为这应该让你们更接近一点。