Support

Account

Home Forums ACF PRO Relationship between 3 CPTs

Solved

Relationship between 3 CPTs

  • (Pre-post: Salutations to the greatest plugin of all times, sweet words appraising the devs and many other kind stuff too! :D)

    Hello,

    I am trying to create a relation between 3 Custom Post Types

    CPTs:
    A) Universities
    B) Faculties
    C) Study-Programmes

    Relations:
    A -> B) A University can have many Faculties
    B -> A) A Faculty belongs to a University

    A -> C) A University can have many Study-Programmes
    C -> A) A Study Programme belongs to a University

    B -> C) A Faculty can have many Study-Programmes
    C -> B) A Study Programme belongs to a Faculty

    Notes:

    • I have already installed the acf-post2post add-on, on top of my ACF-Pro
    • I have also installed the ACF-Extended

    What i ve done:
    Created a Relationship-cf in both [A] and [B] (same name, same settings).
    A->B and B->A work. When i go to a [single University post] and add Faculties, it shows them on that [single Faculty post]. In the same manner, if i delete universities from a [single Faculty post] and visit that same [single University post], they are deleted.

    I have done the same for [A] and [C] and A->C and C->A work.

    Where i fail:
    I cant get the B -> C and C -> B relationships going. I have done the same thing as i did previously (relationship cf with same name, same settings)

    Is it because i can only have unique relations between these and i have already used [B] and [C]? Is it possible at all to have this circular relationship at all?

    Please forgive me if using any erroneous or non-technical terms to describe the relationships, i am not exactly a Computer Science person.

    Thank you so much!

  • If I understand what you war doing then you do not need the third relationship. You only need:

    Universities <=> Faculties
    Faculties <=> Programs

    if you want to get Universities from programs you get the faculties relationship and then get the Universities relationship form the faculties posts

    if you want to get the programs for universities then you get the faculties and then get the programs for each faculties.

    If you really want to have it circular then you need to have 3 relationship fields and each post type will need to have 2 fields where you select the other 2 post types separately.

  • Oh thank you for taking the time to post!

    After reading your answer i realize that not only i dont really need a circular relation but the circular relation does not work as i want.

    It cant work because:

    From a University, i am able to add/remove a Faculty from my field. (also the other way around)
    From a Faculty, i am able to add/remove Programmes from my field. (also the other way around)
    From a Programme i am able to add/remove Programmes from my field. (also the other way around).

    But the associated programmes between Faculties <-> Programmes are different than the associated programmes between University <-> Programmes. (because it requires 2 unique relational fields, not 3)

    It is a relief to know that Faculties can act like the middleman, the connector that associates Universities and Programs and i can go back and forth from A to C through B with PHP. So if University has Faculties and Faculty has Programmes, by association, a University has Programmes.

    What i was looking for is to be able to add/remove Programmes from University (also the other way around).

    From a University, i am able to add/remove a Faculty from my field. (also the other way around)
    From a Faculty, i am able to add/remove Programmes from my field. (also the other way around)
    But i am unable to add/remove Programmes from University (also the other way around).

    That is what i really need.

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

You must be logged in to reply to this topic.