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.
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.
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.
You must be logged in to reply to this topic.
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!