Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jcjdamen opened this issue Jun 23, 2024 · 0 comments
Open

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

jcjdamen opened this issue Jun 23, 2024 · 0 comments

Comments

@jcjdamen
Copy link

jcjdamen commented Jun 23, 2024

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*

@jcjdamen jcjdamen changed the title Issue with repeater on front end [fixed / remove] Issue with repeater on front end Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant