Support

Account

Home Forums General Issues Relationship fields filtering over next relation

Solving

Relationship fields filtering over next relation

  • Hi, ‘m planning to develop a system based on custom_post_type of 3 base kind:

    – Event;
    – Appointment;
    – Person;

    Event is my base value.
    Each Appointment can have max 1 relation with an Event.
    Person can have only 1 relation to Event but several appointments.

    I’m wondering to create a custom structure for Person where:

    – I select the base Event as Relationship;
    – Once I did it the next field of Appointments will be filtered using the Event selected (looking at the relation inside the custom_post Appointment that links Event & Appointment);

    This is what I’m looking for, but atm I haven’t figured out yet how to do this and if I can do this using ACF.

    Do you have any hint? Suggestion to reach my goal?

    Thanks!

  • Hi @mmn

    Thanks for the question.

    Lets assume you are on the edit page for a person, and you want to select 1 event and then 1 Appointment.

    You can use ACF to create the Event field (post object field). This will show all Events posts and allow 1 selection.

    Next, you need to update / populate the Appointment select field. I would create this as a select field with no choices, and rely on JS to populate is after an Event has been selected.

    You could write a jQuery event for the Appointment Change, and then get the Appointments via AJAX, then just update the Appointments select DOM object with the results.

    Good luck!

    Thanks
    E

  • Hi @elliot, can I ask you how to create a hook for populating the select field? I’d assume that the best tut that explain my needs is this one: http://www.advancedcustomfields.com/resources/tutorials/dynamically-populate-a-select-fields-choices/

    Is it correct?

  • Hi @mmn

    Yes. The link you have posted is a good tutorial to follow if you want to populate a select field’s choices dynamically. Please note that this will not create any jQuery / AJAX functionality, and will only work on page load.

    Thanks
    E

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

The topic ‘Relationship fields filtering over next relation’ is closed to new replies.