Support

Account

Home Forums Front-end Issues Post object inside a repeater field Reply To: Post object inside a repeater field

  • Turns out – as usual with me – it was much simpler. I used a Woo shortcode that displays products (the way i wanted, with all the product details) and put it inside the loop that gets the PostID for the three products, set the PostID to a var, and it is almost working.

    It is working, except i need to adjust the loops syntax somehow:

     // check if the repeater field has rows of data
        if( have_rows('products_to_display_repeater') ):
    
            // loop through the rows of data
            while ( have_rows('products_to_display_repeater') ) : the_row();
    
                // vars
                $product_id = get_sub_field('product_complete_the_look');
                
                // get IDs from vars for Woo shortcode
                echo do_shortcode("[products ids='$product_id' limit='1' columns='1' orderby='date' order='desc']");
    
                // display a sub field value
                ?> 
                <?php the_sub_field('product_complete_the_look'); ?>
                <br>
                <?php 
    
            endwhile;
    
        else :
    
            // no rows found
    
        endif;

    The above works but because of echo do_shortcode("[products ids='$product_id' limit='1' columns='1' orderby='date' order='desc']"); I get three products each as 1 column and 1 row. I need one row with three columns.

    So the shortcode is being looped and called three times, once for each PostID. I need to only call the shortcode once and loop only the '$product_id' within the shortcode, thereby have three PostIds in the shortcode. Oh and they need to be comma separated.

    If anyone has input that’s great but I might figure it out…