AdvancedCustomFields / AdvancedCustomFields/acf

Gutenberg/Block-Editor meta-block REST-API update mechanism for ACF-Fields?

Open
#687 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Gutenberg allows to save block-values to the post meta ( https://developer.wordpress.org/block-editor/how-to-guides/metabox/#step-2-add-meta-block ).

However, it seems currently impossible to update ACF fields using a meta-block without using a "hack" - that ist replicating the value entered into the meta-block into the key's input field in the ACF metabox - prior to saving the page/post. If the two values differ at the moment of saving, the one in the metabox is apparently saved last, so will take precedence. So unless that value is synchronized with the value entered into the meta-block, the old field-value will be saved instead of the new one.

Using the relevant part of the linked post above, to update the field "legacyField", something like

document.getElementById("acf-field_62f99453a7fa3").value = newValue;

would have to be included in the meta-block update function:

`const [ meta, setMeta ] = useEntityProp( ‚postType‘, ‚postType‘, ‚acf‘ );
const metaFieldValue = meta.legacyField;
const updateMetaValue = ( newValue ) => {
setMeta( { …meta, legacyField: newValue } );
document.getElementById(„acf-field_62f99453a7fa3“).setAttribute(‚value‘, newValue);
};

This post -

https://wordpress.stackexchange.com/questions/408053/update-post-meta-custom-field-using-block-editor

describes the problem for the regular custom field UI in WP. Alas, the suggested workaround will not work for ACF, because using ACF field groups for a post type will create the respective metaboxes, even if they are not shown in the block-editor.

I'm not aware of another way to solve this problem.
Is there?

Otherwise, I suppose it would be better to be able to indicate on a field-group or even field-by-field-basis wether the field should actually appear in a metabox or the update would have to be done through a custom block.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Gutenberg meta-block guide, the ACF metabox save behavior described in the issue, and the linked WordPress StackExchange discussion. Reproduce the conflict between the meta-block value and the ACF field value, then define whether a supported synchronization mechanism or a field/metabox configuration is needed; done means the selected behavior is documented and verified without the described workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php, wordpress
Domain
api, backend, content
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.