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

Latest ACF issue #39

Open
marziolek opened this issue Oct 24, 2022 · 6 comments
Open

Latest ACF issue #39

marziolek opened this issue Oct 24, 2022 · 6 comments

Comments

@marziolek
Copy link

marziolek commented Oct 24, 2022

https://github.com/pristas-peter/wp-graphql-gutenberg-acf/blob/develop/plugin.php#L86
$root['attributes']['id']
should be updated with
$root['postId']
If there are no inner blocks. There should be some check for inner blocks or just simple check like this

$inner_id = $root['postId'];
if (array_key_exists('id', $root['attributes'])) {
	$inner_id = $root['attributes']['id'];
}

acf_setup_meta(
	$root['attributes']['data'],
	$inner_id,
	false
);

return $inner_id;

ACF Pro 6.0.3

@marziolek
Copy link
Author

Also there is no release with latest updates.

@JoeStantonCode
Copy link

The solution @marziolek works. However, whenever you have the same block on the page. It duplicates the data. Any fixes for that? As you can see I have the Story Block twice on the same page and the data is duplicated.

Screen Shot 2022-10-31 at 4 50 09 PM

@MKlblangenois
Copy link

https://github.com/pristas-peter/wp-graphql-gutenberg-acf/blob/develop/plugin.php#L86 $root['attributes']['id'] should be updated with $root['postId'] If there are no inner blocks. There should be some check for inner blocks or just simple check like this

$inner_id = $root['postId'];
if (array_key_exists('id', $root['attributes'])) {
	$inner_id = $root['attributes']['id'];
}

acf_setup_meta(
	$root['attributes']['data'],
	$inner_id,
	false
);

return $inner_id;

ACF Pro 6.0.3

Hey @marziolek, this solution seem to solve the "null" result issue, but like @JoeStantonCode, when you use a block twice in the same page, all fields take the first block iteration as value.

Append with ACF Pro@6

@webprogrammingsolutions
Copy link

webprogrammingsolutions commented Nov 18, 2022

@MKlblangenois do you have any suggestions on how we can handle repeaters? We are trying to pull in repeater data from an ACF Options screen and still reciving null values.

{footerBlocks.map((item: any, key: any) => ( <div className="contact-form-footer__item" key={key}> <b>{parse(item.headline)}</b> {parse(item.text)} </div> ))}

footerBlocks being the repeater.

@wahyuang
Copy link

wahyuang commented Jan 3, 2023

The solution @marziolek works. However, whenever you have the same block on the page. It duplicates the data. Any fixes for that? As you can see I have the Story Block twice on the same page and the data is duplicated.

Screen Shot 2022-10-31 at 4 50 09 PM

Hi, I got the same issue regarding duplicates data. Do you guys have any workaround to solve this?
Thank you

@wahyuang
Copy link

wahyuang commented Feb 13, 2023

For anyone who still looking for solution of duplicate value issue, this code might help.

add_filter( 'acf/pre_save_block', 'add_acf_block_identifier' );

function add_acf_block_identifier( $attributes ) {
        if ( empty( $attributes['id'] ) ) {
            $attributes['id'] = 'acf-block-' . uniqid();
        }
        return $attributes;
}

Add this block code to your functions.php on your theme or create a custom wordpress plugin.

This issue caused by missing block id on Custom Gutenberg Block by ACF, since ACF 6.0 no longer save block IDs. Ref to this article here

Hope this will help other. Happy coding :)

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

5 participants