StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
794 stars 62 forks source link

[fixed / remove] Issue with repeater on front end #185

Open jcjdamen opened 4 months ago

jcjdamen commented 4 months ago

Hi all,

I have created a custom post type to which various fields have been added, including a repeater field. I use an ACF Gutenberg block to load this data in a regular blog post, passing the ID of the CPT post. This block works correctly in the backend (Gutenberg editor), but the repeater field data is not displayed correctly in the frontend. When I var_dump the repeater field, it shows true in the backend and false in the frontend. However, if I manually create the fields in ACF and export them to PHP, it works correctly in both the backend and frontend.

Could someone please help me understand if I am doing something wrong or if this is a bug?


<?php
        $productInfoBuilder = new FieldsBuilder('uta_product_info');
        $productInfoBuilder->setLocation('post_type', '==', 'affiliate_products');

        // Fields
        $productInfoBuilder
            ->addText('product_search_ean', [
                'wrapper' => ['width' => '20'],
            ])
            ->addSelect('product_search_merchants', [
                'wrapper' => ['width' => '20'],
                'choices' => $this->getActivePlatforms()
            ])
            ->addText('product_search_value', [
                'wrapper' => ['width' => '60'],
            ])
            ->addRepeater('merchant_info', [])
                ->addText('product_name', [
                    'label' => "Name",
                ])
            ->endRepeater();

        acf_add_local_field_group($productInfoBuilder->build());
?>

<?php
$productID = 7;
var_dump(get_field('product_search_ean', 7)); // returns 1234523456
var_dump(have_rows('merchant_info', 7)); // returns false in front, true in admin

if(have_rows('merchant_info', 7) ):
    while( have_rows('merchant_info',7) ) : the_row();
        $sub_value = get_sub_field('product_name');
        echo 'product name: ' . $sub_value;
    endwhile;
endif;
?>

Edit: fixed! Forgot to load the class * facepalm*