Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Must click "Update" twice to save values to post_meta

Abierto
#996 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
javascript, php
Área
backend, web-dev

Línea de trabajo

Empieza reproduciendo el flujo de actualización del bloque con acf.getField(), field.val() y field.$input().trigger('change') en el ejemplo del issue. Inspecciona cómo gestiona la ACF JavaScript API los cambios de valor y confirma que el primer Update persiste el valor en post_meta sin una edición manual.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

UPDATE 2:

Properly triggering a change event on the input also solves the issue. DO NOT trigger an event on a jQuery selector of the input (like I tried a million ways).

let field = acf.getField('field_123456');

// trigger change event on $input()
field.$input().trigger('change');

UPDATE:

Works fine if I set a value attribute on the input element. Plain javascript because jQuery's prop() and attr() didn't seem to work.

let field = acf.getField('field_123456');
field.val('some value');

// add value attribute to input
document.querySelector('.acf-field[data-key="field_123456"] .acf-input-wrap input').setAttribute('value', 'some_value');

I'd still love to understand the original issue. Maybe some sort of "dirty" status that's not set when using ACF val() but is set when editing the field manually?


Describe the bug

Wondering if anyone has any insight on a custom ACF block issue? ("blockVersion": 3, "usePostMeta": "true"): values set in block with javascript are not saved to Db unless Update is clicked twice.

Within wp-admin, editing a post:

  1. I set a field value via javascript while a block is being edited:
let field = acf.getField('field_123456');
field.val('some value');
  1. I see the value in the text input on-screen
  2. I click "Update" for the post, but value is not written to dB. ***
  3. I click "Update" a second time, and value IS written to the database.

*** If I manually place the cursor in any field in the block and add/delete a character, THEN values are saved the first time I click "Update"

Sure seems like ACF triggers some event/condition when there's a manual edit, but NOT when the value is changed via the ACF JS API.

What is that event/condition? I've had no luck figuring it out...

To Reproduce
See above

Expected behavior
When I click Update the first time to save the post, the values set via the ACF JS API are saved to the db.

Version Information:

  • WordPress Version [6.9.1]
  • PHP Version [e.g 8.5]
  • ACF Version [e.g ACF PRO 6.7.0.2]
  • Browser [all of them...]

Additional context
I've submitted a ticket, and searched the forum but did not find this issue.

Lenguaje dominante
PHP
Estrellas
946
Forks
197
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de AdvancedCustomFields/acf

Todos los issues de AdvancedCustomFields/acf

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.