I am looking to be able to dynamically populate checkboxes fields (both on Post Fields and Term Fields) with the terms of a custom taxonomy.
I've seen a few solutions on the forum, but these all appear to be written to populate a dropdown field. Is there a way I can adapt this to populate a checkboxes field?
Hi, unfortunately there is not currently a built-in way to dynamically populate field options in wp-admin field editors using the terms of a taxonomy. There is no documented API that allows this functionality. The only workaround I'm aware of is on the front-end of the site, where you can use generic fields in Forms. You can create a generic checkboxes field that uses a View of taxonomy terms to set the field options dynamically. However, this approach only works on the front-end of the site, and does not automatically adjust the available checkboxes field options in the backend of the site. You must continue to manually adjust those as needed.
Thank you for your reply Christian.
So the code used in the two below threads could not be adapted for use with a checkboxes field? They seem to be doing exactly what I wish to achieve but with a select field. Please correct me if I have read the threads wrong, you guys know a lot more than me!
https://toolset.com/forums/topic/dynamically-populate-select-field-with-custom-taxonomy/
https://toolset.com/forums/topic/filling-a-select-box-from-terms-in-a-taxonomy/
While the code can theoretically be adapted for use with checkboxes, the code utilizes an undocumented filter "wpt_field_options" to modify the options in each custom field. Undocumented filters are not technically supported, so I can't recommend using them. We have found that the wpt_field_options filter can cause unexpected problems with custom searches, so we do not recommend it any longer.
Thank you Christian!
That makes perfect sense. I think I will stick to inputting these options in the manual way to avoid the chance of any problems down the line.
Thank you for all your help.