I'm working on a plugin that includes a custom post type, by default this CPT will not be associated with any taxonomies.
On the Settings page for the plugin I'm looking to show a list of the existing taxonomies on that WP instance and allow the admin to select which (if any) of those existing taxonomies (both built-in and custom) they'd like to associate with this plugin's CPT.
I'm primarily wondering if anyone knows of existing solutions/code snippets/articles on this problem?
I found Fred Meyer's article on adding existing taxonomies to WP CPT's, but it assumes that we know the list of taxonomies whereas in this case they need to be discovered on each admin's wp instance.
I should be able to use
get_taxonomies() to get the list of taxonomies dynamically.
Theoretically I can then:
- Display the list of taxonomies as settings on the plugin's setting's page.
- Allow the individual to select one or more of these taxonomies (using checkboxes or perhaps a multi-select?).
- Iterate through the checkboxes/multiselect, adding and removing taxonomies using
register_taxonomy_for_object_type()to associate/deassociate the taxonomies from the CPT.
I can figure it out, but it is the end of the day, so if before I get a chance to work on it again someone knows of some helpful code/article/etc. that will allow me to avoid reinventing the wheel, I'd appreciate it.