Support

Account

Home Forums Backend Issues (wp-admin) How can I dynamically filter the choices in a taxonomy select in global settings

Helping

How can I dynamically filter the choices in a taxonomy select in global settings

  • I need your help, because, I can’t add new fields or edit existing fields with relational type (or relationship type or page_link type) in ACF group settings (post type = acf-field-group) due to values of taxonomies terms in the dropdown list..

    Indeed, in my database I have a lot of entries in database for some taxonomies name (+ 200K) and when the dropdown list is loading inputs results in the memory overflow (PHP Memory limit is exceeded) and AJAX queries results in an HTTP 500 internal error.

    I don’t find the good way to customize the rendered of the field “Filter by Taxonomy” from the ACF group page settings (this field appears when I select a relational type like “post object“, “relationship” or “page_link” in the field type).

    I would like to remove some terms before renderer the dropdown list according a specific taxonomy name (in particular taxnomies names that have a lot of terms), for this, I need to change the query filter…

    Solution 1 :

    I’ve tried to add and implements code using these hooks :

    • acf/render_field_settings/type=post_object
    • acf/render_field_general_settings/type=post_object

    but using these hooks I cannot customize the data in the select field for taxonomy filter…
    I can only add new custom settings fields…

    Solution 2 :

    I found this hook in the plugin code : wp_ajax_acf/field_group/render_field_settings to customize the sections built, I have added custom functions to display data in the select according the type (p<ost_object, relationship and page_link), but this implementation works only at the creation of a new field and not when I am editing an existing field in ACF group.

    Also, I don’t think this find is a good practice for future versions of the plugin (this is was not documented in the official documentation) and I’m afraid that this action leads to undesirable side effects…

    Another solution would be to limit the number of results in the dropdown rather than loading everything at once, but I can’t find documentation on this…

    Has anyone had this problem before? Can someone help me ?

  • to filter the posts available in a relationship field use the hook acf/fields/relationship/query.

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

You must be logged in to reply to this topic.