Home Forums Bug Reports ACF Gutenberg blocks and JSON API do not work Reply To: ACF Gutenberg blocks and JSON API do not work

  • We are you using a lot ACF blocks in gutenberg and we found an issue with it in the WP JSON API.

    When you are creating ACF blocks and copy them to other pages the blockID is the same.

    Then we have a function for the register_rest_field to get the blocks in the REST API so we can sync them to our frontend.

    We do so like this:

    $blocks = parse_blocks( $post->post_content );


    acf_setup_meta( $block[‘attrs’][‘data’], $block[‘attrs’][‘id’], true );

    $fields = get_fields();

    acf_reset_meta( $block[‘attrs’][‘id’] );

    When you ask for a batch pages in the REST API like this:

    The block field for all the pages on the URL will have the exact same ACF values as the first page.

    The bug is in acf-value-functions.php

    – function acf_get_value (rule 91-92)
    – function acf_format_value (rule 143-144)

    Here you they are posting values to the store with this code:

    // Update store.
    $store->set( “$post_id:$field_name:formatted”, $value );

    The problem is the $post_id for ACF blocks is the blockId which is not unique if you copy ACF blocks from page to page.

    The solution would be to make the store something like this:

    // Update store.
    $store->set( “$post_id:$block_id:$field_name:formatted”, $value );

    This way you have the real post_id and the block_id and the store key will be unique.