ACF: If field contain a specific value, update value in another field programatically

how can I change the value of a field based on the value of another field programatically?

This other field has already a value but I need to replace / update it.

To be more precise:

If the Text Field named type has value Houses AND another Text Field named service has value 2, this should be updated in NOT AVAILABLE.

Or ...

If the Text Field named type has value Parks AND another Text Field named service has value 2, this should be updated in AVAILABLE.

Or ...

If the Text Field named type has value Store AND another Text Field named service has value 2, this should be updated in COMING SOON.

I read the update_field doc but I could not solve this.

Topic advanced-custom-fields Wordpress

Category Web


Did you trying something like this in a JS script?

Assuming you wants to edit the service text field.

jQuery(document).ready(() => {
  const textfield_type = document.querySelector('input[name="type"]');
  const textfield_service = document.querySelector('input[name="service"]');

  const updateField = () => {
    if (textfield_type.getAttribute('value') === 'Houses' && textfield_service.getAttribute('value') === '2') {
      textfield_service.setAttribute('value', 'NOT AVAILABLE');
    }

    // ... other rules
  }

  // Launch the event only if the two fields exists
  if (textfield_type !== null && textfield_service !== null) {
    textfield_service.addEventListener('focusout', () => updateField());
  }
});

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.