WPLift is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

How Post Relationships Can Help Build Advanced Sites – Doctors And Patients Example

Last Updated on June 14th, 2019

Published on May 29th, 2018

Tags: ,

Share This Article

Tools which help you save time are generally a precious commodity – for developers they are priceless.

Toolset has added two new features which will not only see you working smarter than ever before but will also make it easier to create websites which look more professional than ever.

The first is the addition of post relationships. Post relationships are connections between unrelated posts, making it easier to run really advanced websites. That is because you can separate the elements within your custom post types and combine them in many different ways. With post relationships, you only need to post information once – avoiding data duplication – while using it as many times as you want on your website.

The second feature is repeatable field groups which will help you create a group of custom fields which you can use over and over again within a custom post type. Rather than wasting time creating the same set of custom fields, developers can create a repeatable field group once and reuse it as they please.

Within this post, we will use our patient/doctors demo website to explore the following:

  • The different types of post relationships
  • How to create a many-to-many relationship
  • Building a form to create connections on the front-end
  • How repeatable field groups make it easier to add content

What are the three types of post relationships

You can use Toolset’s post relationships feature to create three different types of relationships. Each one has their uses which we will now outline.

The one-to-one relationship

In a one-to-one relationship, elements from two different custom post types will be connected exclusively.

one to one

To illustrate, on a doctor’s office website, a patient will want to book an appointment. We can create an exclusive relationship between the appointment and the patient which reserves it. For example, Paul K (a patient) might choose to be seen at 10am on May 5. When he selects that slot staff will be able to see his appointment on his “Patients” post and will also see Paul’s name next to the 10am, May 5, slot on the “Appointments” post. This all happens with just one click from Paul.

One-to-many relationships

We will use a one-to-many relationship to link a singular item from one custom post type with multiple items from another.

Besides making appointments, patients might want to access certain test results online too. We already have our “patient” custom post type so we would have to create one for test results. Each of the items within the “test results” custom post type will be unique for one particular patient. However, patients will probably take more than one health test. Therefore, a one-to-many relationship is the best option.

Article Continues Below

one to many

Many-to-many relationships

For complete flexibility when building and running websites, the many-to-many relationship is by far the best feature. Using this relationship allows an item from a custom post type to be connected with multiple from another post type and vice versa.

On our doctor’s office website we will want to link items from our “patient” and “doctor” custom post types with many elements from the other. Doctors will obviously have multiple patients while patients might need to see various doctors depending on their condition. Therefore, it is important to create a connection between the two in order to make it as easy as possible to add patients to a doctor’s list, for example.

The great thing about many-to-many relationships is that if we need to update an item from a custom post type we do not need to go through every single post to ensure they are correct. We can also use this feature to implement searches which include or exclude certain items from a custom post type – you can easily search for doctors who are not already assigned to a patient, for example.

Let’s take a look at exactly how you can create a many-to-many relationship using our doctor’s office website.

How to create a many-to-many relationship

We will use Toolset’s relationship wizard to create our many-to-many relationship. One of its advantages is that we do not need to use PHP or any other coding to forge these connections.

Once we have opened the relationship wizard on Toolset we can start to create our many-to-many relationship between our “patient” and “doctor” custom post types. The first step is to select what type of relationship you want on the first screen – we will choose the many-to-many relationship option.

select relationship type

We now need to choose which custom post types we want to connect with each other. In this case, it will be the “doctors” and “patients” post types.

select post types

On the next screen, we can limit exactly how many items from a custom post type we can connect with the other. Let’s imagine that we do not want each doctor to have more than 200 patients assigned to them otherwise they would be far too busy. Here is where we can place that restriction. We will also only allow a patient to be registered with three doctors.

set custom limits


Article Continues Below

On the next step, you can add extra fields which are specific to this relationship. For our doctor/patient connection we will want both sides to know the date of their appointment and what the treatment will be for. Therefore, we can create two fields to represent this. With Toolset, we have a variety of different field types to choose from.

add new field

Once we select and name them we are left with our chosen two fields.

relationships fields

The last step is to name our new post relationship. We will simply call it “Patients and doctors.”

relationship wizard naming it

Once we click “Continue” our new post relationship is ready to be put through its paces. Let’s imagine that Paul K. has a heart condition and we need to assign him to a cardiologist. We can now create a connection between his “patient” custom post type and the “doctor” one for Yann Tailor, the cardiologist.

There are two options to add connections. The first is by selecting the “Add new doctor” option and creating a new “doctor” custom post type. However, we have already created Dr. Tailor´s post, therefore, we will use the “Connect existing doctor” option.

add doctors

Once we click on there we can select Dr. Tailor’s name while also adding a date and treatment option using the relationship fields we previously added.

add relationship connection

Now that we have created the new connection, Paul K’s post has been updated to include Yann Tailor.

Paul k front end

However, there is another way that you can create new connections between the “doctors” and “patients” post types without having to access the back-end.

How to create a form to add relationships on the front-end

We can use Toolset’s relationship forms to create a form which we will allow our patients or doctors to assign themselves to each other on the front-end.

Article Continues Below

We can build it under the relationship form section within Toolset. First, we simply need to name our new form, which we will call “Doctors patients form.”

create new form

On the next slide, we need to choose exactly which post relationship we want to use for the form and what happens once the user submits it. We will select the “Doctors Patients” form and ensure that users will stay on the same page once they click submit.

form building doctors and patients

It’s now time to actually build the form. We will use the “Autogenerate form content” option which will automatically create our form for us without requiring us to input any coding. As you can see below, we simply have to select which fields we want to appear. We only need the “Doctors” and “Patients” post types so we will remove the relationship fields.

autogenerate form content

Below is how our form now looks on the back-end. Once again, you will see how we have not added any CSS.

form content

We can now create relationships between our “Doctors” and “Patients” post types just like we did before on the back-end. Observe how easy it is to add Ella T to Yann Tailor on the front-end.

Doctors patients form

When we head to Ella T’s post we can see, once again, that Dr. Tailor is now listed as one of her doctors.

ella t front-end form

The problem we now have is that when patients access their post they will expect to see certain information such as x-ray results. Luckily, we can use Toolset’s other feature to make it simple to add them.

Use repeatable field groups to easily add content

Using repeatable field groups makes it easy to add the same set of fields over and over again without wasting time adding each one individually. Let’s look at an example.

Whenever a patient receives results of an x-ray, we want to upload the images and details of the x-ray to their post to allow both patients and doctors to easily view them. Rather than adding each of these individual elements every time we want to upload a new x-ray, we can create them once as a group. Therefore, we will create a repeatable field group which we can display as a slideshow on the front-end. We can combine the fields to create one group which we can use each time we need to add a new x-ray. For this purpose, we have three fields: the image, the date of the x-ray and a brief description of the body part.

repeatable field group back end

As you can see below, instead of creating each of the fields whenever we need to upload an x-ray, we can click the “Add new X-ray slider option” to see all the fields we need.

repeatable field group slider

Any new slides we create will then show up on the front-end.

paul k with slider

As you can see, using the repeatable field group feature will save developers a considerable amount of time when it comes to adding similar types of content to a page.


Both of Toolset’s new features, post relationships and repeatable field groups, will not only help you build websites which will look professional but they will cut down on the time it takes to create them. Better results quicker than ever? Now that really is a win-win situation.