Support

Account

Home Forums Pre-purchase Questions Newby Pre-Sales Question – The Nature of ACF & WordPress

Solved

Newby Pre-Sales Question – The Nature of ACF & WordPress

  • Basically my question revolves around how this all works…

    Say for example I create 2 custom post types with the following fields:
    1. RESIDENT
    —–RESIDENT NAME FIELD
    —–APARTMENT NUMBER FIELD (linked to below field/containing data from APARTMENT CPT)
    2. APARTMENT
    —–APARTMENT NUMBER FIELD
    —–RESIDENT NAME FIELD (linked to above field/containing data from RESIDENT CPT)

    AND each of the above custom post types will contain data from the other. So for example, a RESIDENT may be assigned to an APARTMENT, giving them an APARTMENT NUMBER and vice versa…

    So now for example, when I create a RESIDENT named Anita and how can I give her an APARTMENT NUMBER (ie. LINK the two data to each other so they work properly together throughout the front and back-ends of the website)?

    Is this something I need to code EXTRA or does all of this happen automatically via the settings in the plugin?

    Do I need to use the RELATIONSHIP FIELD for this or is that for something different?

    So, when I go to add a new RESIDENT via the Add New Resident Admin page and then how can I then add the APARTMENT NUMBER in such a way that it will pre-populate from the already currently available APARTMENTS already added or the other way around, when I go to add an APARTMENT, I can then add the RESIDENT from a pre-populated list of already added RESIDENTS?

    So I hope this is making sense here…

    So I am assuming that I can add all the data in the back-end and then create the template pages programmatically to pull whatever data I need for the front-end, and I get that, but my question arises when I am creating them in the back-end, will they be aware of each other (linked) or will I have to manually update each custom post types additions to reflect the status of the other essentially having to remember to update the APARTMENTS data to reflect any newly added RESIDENTS and vice versa any time a new one is added so that – that data will be available to pull from on the front end..? ..but then this would essentially mean every time a new RESIDENT is added, I would have to add content twice, manually going into the linked CPT to then like it from the reverse side…(OMG I don’t know if I am explaining this properly!!!)

    Ok, well this is getting so long and confusing. I hope this is making sense to somebody!!

    Thank you in advance to anyone willing to offer an answer or even some insight!! It will be very much appreciated!!

  • It is better to think of each post as a separate things.

    You would only add data to the apartment post that is specific to that apartment, and this would not include anything about the resident.

    The same for the resident, it would only include information specific to that resident and nothing about the appointment.

    These would be linked using either a relationship field or a post object field, based on if you want a 1 to 1, many to many, or 1 to many relationship. There is functionality for this in ACF and also some 3rd party plugins, depending on your needs, it is refereed to as a “bidirectional relationship“. This only works in the admin. You cannot create a post of the related type while editing a post (There is a 3rd party plugin that can let you do this https://www.acf-extended.com/features/fields/relationship)

    The posts on each side of the relationship are not “aware” of the post on the other end except to this bidirectional field. One post does not know what content the other post has and the data is not automatically shared between the posts.

    The above is in the admin only. In the template for each of these post types you would get this field and then use what is returned to get values from the post at the other end of the relationship. Doing this is covered in the relationship field documentation https://www.advancedcustomfields.com/resources/relationship/

  • Thank you so much for explaining all of this! This is completely invaluable and amazing. I can’t wait to jump right in and go through all your links. This is so great cause you really explained this in such a way as to enable me to know exactly what I am dealing with now so in case the links you included aren’t exactly the answer this answer was exactly the answer lolo, so now I know even how to research this more as well as you could see I was even struggling with the right words to describe all of it and the way you explained that helps me with that as well. 10 Stars my friend. Thank you so much for taking your time out on this… HAPPY HOLIDAYS to you as well!!

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

You must be logged in to reply to this topic.