Support

Account

Home Forums Backend Issues (wp-admin) Relationship field – filter choices with AJAX Reply To: Relationship field – filter choices with AJAX

  • I’m probably as close as you’ll get to an answer to this. The only real way to filter a relationship field is to use the acf/fields/relationship/query
    filter https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

    Getting the value and doing your own custom AJAX request I can help you with. In the scenario you describe, and this is the part that I don’t know, you would need to figure out how to add the value of the selected post to the AJAX query that ACF is already doing. For that you’d probably need to do a lot of digging around in ACF JavaScript and I have no idea if it’s possible.

    If I were going to do this I might use a relationship field for the first choice but I would probably use a select field for the second field, only because it’s a whole lot easier.

    This example of mine shows how to populate other fields based on the selection in a relationship field https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-fields-on-relationship

    This example shows how to populate the choices of a select field based on a selection in another select field https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example

    Like I said, I don’t know how to modify the AJAX request that ACF makes for a relationship field or how to trigger that request when another relationship field is changed. More than likely it’s possible, depending on your JS skills and how much time you want to spend digging through ACF to figure out how.

    Hope this helps in some way.