Support

Account

Home Forums General Issues Dynamically Filter Post Object Dropdown?

Helping

Dynamically Filter Post Object Dropdown?

  • Hello,

    So I have a CPT called Resources, and there are 2 ACF fields (selects). One select to chose the “Industry” and the other to chose the “Department”.

    Then on my default page template, I want to give the user the ability to feature some resources. Normally I would just use the Post Object field type, allow multiple selections and filter by the Resources CPT.

    BUT….

    Now I’m being told that there could be up to a hundred resources or more, and feel it would be bothersome to have to scroll though the entire list in the Post Object drop down they see when on the page edit screen.

    So anyways, now I’m being told to add the same 2 grouping fields (department and industry) to the default page template. And based of what is selected, the list of resources that returns in the Post Object dropdown will be filtered to only show resources that had the same selections (department and industry select fields).

    So basically, I need to know if anyone could give me some advice on how to filter the post object dropdown field on the page edit screen, based off selections from 2 other fields.

    Normally, I would just push back and say the work (cost) isn’t worth the payoff. But I’m actually pretty curious if anyone has done something like this or at least can point me in the right direction.

    Any help would be much appreciated.

    Thanks!

  • There isn’t a way that I know of to filter a post object field based on a selection in another field or fields, at least not built into ACF. A post object field is a select2 field and the contents of this field are generated by an AJAX request. Information from other fields is not sent in that AJAX request. There might be a way to alter the alter the request, but nothing that I can remember has ever been posted here about how to do it and I have not been able to figure that out. If you can figure out how to alter this AJAX request then you could use https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/ to get the additional information from the request ($_POST) and alter the query.

    More than likely, if I needed to do this in a hurry I would use a basic select field rather than a post object field and I’d build custom JavaScript and a custom AJAX function to allow me to filter the list shown in this field. I have an example of this here https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example

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

The topic ‘Dynamically Filter Post Object Dropdown?’ is closed to new replies.