Support

Account

Home Forums ACF PRO Link ACF Relationship fields between Custom Post Type

Solving

Link ACF Relationship fields between Custom Post Type

  • Hello !

    I have a website that articulates likes this :

    • A custom post type “Shop”
    • A custom post type “Product”
    • A custom post type “Service”

    Each custom post type will be linked to each other with one or two relationship field(s) like that :

    • When the admin will create a “shop”, he will be able to link the current shop to one or more “product(s)”.
    • When the admin will create a “product”, he will be able to link the current product to one or more “shop(s)” AND to one or more “service(s)”.
    • When the admin will create a “service”, he will be able to link the current service to one or more “product(s)”.

    Here is my question : when, for example, the admin create a “shop” that will be linked to a “product” and save, the linked product has to be also updated so that its relationship field show the newly created shop.

    Is there a code example to do something like that ?

    Thank you in advance !

  • Hi @cedric_charles,

    Would you like to get this functionality on the backend or the frontend?

    Please have a look at this tutorial for the frontend: https://www.advancedcustomfields.com/resources/bidirectional-relationships/

  • Hi @acf-support !

    It’s in the back-end. In the front, I can do the ckecks. But the link you gave me is for the back-end no ?

  • Hi @cedric_charles

    I’m sorry it was a typo. Yes, the tutorial in that link is used on the backend.

    Thanks πŸ™‚

  • Thank you, I’ve adapted the code for two different relationship fields in two different custom post types and it’s working well, thank πŸ™‚ !

  • Hi @cedric_charles,
    would it be possible for you to share the code for different relationship fields in different custom post types you developed? It’s exactly what I need as I’m trying to set up a database for directors / movies.

    Edit: I just found out the code here works just fine for two interrelated custom post types.

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

You must be logged in to reply to this topic.