Home Forums ACF PRO Cross Reference Relations


Cross Reference Relations

  • Hello Everyone!
    Say I have two custom types (Projects – Designer). In projects, I have say 5 projects. In designers, I have 10 designers. My main post type is projects.

    I would like to connect the two that if I select a designer for a project through the field (relation or post object), the designer will automatically have the project in the same field. In other words, i want it to work like a cross reference between projects and designers.

    Is there any chance for this?

  • Hi Proacfelie,

    It’s totally possible, the right way (and the easier way) to do it depends on what you exacly need : Display relationship on frontend / backend ? Do you used simple relations field or in repeater ?.

    If your in the worst case, Designer and Project posts have both several relationship in repeater and you want to edit and display in backend and frontend (hope it’s will be understandable) :

    Use the WP save_post action. If you save a Project ( Do with If and get_post_type()) loop on your “Designer” repeater field, and for each “Designer” input you found get and loop on the “Project” repeater field of your Designer post. If the project is already in do nothing, otherwise use acf function to update the field and add a new “Project” row. Do the same when want to save the Designer name in the Project post when saving a Designer post.

    There are proper ways to do it if you don’t need the two repeater and/or if you want to query post based on repeater field key.

    If you need other solution or code example tell it.

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

The topic ‘Cross Reference Relations’ is closed to new replies.