Home Forums Backend Issues (wp-admin) Update post meta when ACF checkbox choices change


Update post meta when ACF checkbox choices change

  • Hi,

    I have a couple ACF checkboxes setup for a custom post type.

    I noticed if I delete one of the ACF checkbox choices, the post still shows the choice value until I update the post manually.

    Is there an action that will automatically update post meta if the ACF field is saved/changed?

  • Just checking a box does not cause the value to be saved,

    You would need to add your own custom JavaScript that includes an AJAX request to the site to update the value

  • No sorry, I think you misunderstood.

    In the ACF group settings page, I have a checkbox field with a bunch of choices added.

    If I delete one of the choices in this settings page it is still saved to the post meta of all posts where it was selected until you update each post manually.

    Is there a way to auto-update all the posts when I save the ACF group settings with all the fields?

  • There isn’t any good way to update field values on all posts when you change field settings.

    It is possible if you write PHP. Do a WP_Query() to get all the posts, loop through the posts, get the field, check the values, remove the values for the choices you’ve removed and then update the field if needed.

    If the value must be removed on the front end then I would probably build a check where the field was used in the template rather than try to update all of the posts.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.