Support

Account

Home Forums Backend Issues (wp-admin) Dynamically populating checkboxes from Options page, but with preselected option Reply To: Dynamically populating checkboxes from Options page, but with preselected option

  • For new posts created? Yes. In the same function that you are using to set the choices you can also set the ‘default_value’ to include an array of “Values” and set them all as default values.

    For existing posts? This would be more difficult. I’m not even sure it would be possible. What I’m thinking is: What if the admin has edited this post and un-selected the new value. In this case you would not want to add the value to this page. It would be impossible to check for this condition.

    When a new value is added you could update all posts to have this new value, but it would be problematic if you have many posts that need to be update. It is not scale-able. You can create. You could create an acf/update_value filter for this field on the options page https://www.advancedcustomfields.com/resources/acf-update_value/. In this filter you could compare the old values of the field with the new values of the field and if there is something added you could update any existing posts. You would need to get every post of the post type, loop through them, get the value of the checkbox field, add the new values to the list and then update the field. This is where it will fall apart if you have many posts in the system because it will time out.