0
votes

I have a number of flexible content fields set up.

One of these is called 'product-picker' and another is called 'product-information'.

The product picker uses the post object functionality to pull in selected products.

I can pull in the default wordpress parts such as:

<?php the_post_thumbnail(); ?>

But I can't pull in the values within 'product-information'.

Is this actually possible? Extracts of code below:

<?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; ?>

Then within 'products-picker' I am using the following code:

<?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(); ?>

I might have the structure of my content wrong.

Maybe you can't call flexible content within flexible content?

But I thought it should be possible to do this in light of the fact that the default fields such as:

the_post_thumbnail(); 

and

the_title();

work.

All your time and help is greatly appreciated.

1

1 Answers

1
votes

You have to set up the flexible rows part for each of your post objects. So after you setup your post data, replicate your

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

with the product information fields for each post object.

Check out https://www.advancedcustomfields.com/resources/flexible-content/ and the nested loop example. I think that should get you a little closer.