Home › Forums › General Issues › Dynamic Taxonomy Field based on Dynamic Select Field › Reply To: Dynamic Taxonomy Field based on Dynamic Select Field
It would probably not be impossible to do this, but it would be very difficult and I don’t know how to accomplish it.
If you have custom taxonomies for each post type would be one thing, but on the other hand if you are using a single taxonomy for all post types then it would get even more complicated.
In the latter case, that is using a single taxonomy for all post types, it would probably be impossible to do this and allow for terms to be added in the future and to automatically populate the field based on those unknown future terms. The only way that I can think of to work around this problem would be that if the taxonomy is hierarchical and all of the terms for a specific post type are all children of a main term used for that post type.
If you do have custom taxonomies (or even if you done) then using a taxonomy field is difficult because you would need to intercept the AJAX call that ACF makes to get the list of terms modify the request and inject the selected post type into that request. Then you’d need to build a filter that modifies the get_terms() query that ACF runs https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-query/.
If I needed to do this I would not use a taxonomy field. I would use another select field and I would populate the values of the second select field dynamically based on the selection of the first field as in this example https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!