Learn how to set up post relationship in WordPress using Toolset

April 21, 2016

WordPress doesn’t innately support relationships between posts types. However, by using Toolset you can both connect your posts in relationships and display related posts on the front-end.

This possibility has been in Toolset plugins for a long time, but just recently we have added new step-by-step tutorials to guide you through these concepts easily.

The first tutorial explains one-to-many relationships; the second one, many-to-many relationships. Both tutorials come complete with two training sites where you can test everything yourself or see how we implemented the relationships in the WordPress back-end.

When post relationship is useful

In many cases, different post types are related effortlessly.

Let’s suppose that you are building a WordPress site for Venues, Events and Atists. All this data is related in this way:

  • Events taking place in Venues
  • Artists performing in the Events.

In WordPress these are represented using custom post types and fields.

However, if you connect your post types using relationships you will simplify both the administration of related posts and also the display on the front-end.

How Toolset relationships simplify post administration

When editing a single Artist Post you can connect it with the Events in which the artist will perform.
When editing a single Artist Post you can connect it with the Events in which the artist will perform. .

When editing a Venue Post we can see a list of Events taking place in that venue below. Also we can add new Events from the same screen.
When editing a Venue Post we can see a list of Events taking place in that venue below.
Also we can add new Events from the same screen.

How Toolset relationships simplify displaying related posts

When visiting a single venue page you can see all the events taking place in that venue. See live example.
When visiting a single venue page you can see all the events taking place in that venue. See live example.

When displaying a single artist page you can see all the events in which the artist performs. See live example.
When displaying a single artist page you can see all the events in which the artist performs. See live example.

You can display a page with all artists along with the list of events for each. See live example. See live example.
You can display a page with all artists along with the list of events for each.  See live example.

When visiting a single event page you can see the link to its venue and all the artists performing in that event - see live example
When visiting a single event page you can see the link to its venue and all the artists performing in that event . See live example

The most interesting part is that you can always click on the link of the related post to learn more details about that post.

How to setup post relationships using Toolset

So what do you need to do to enjoy using post relationships in WordPress?

  1. Decide what sort of relationship you will need for given two Post Types – a one-to-many or a many-to-many relationship.
  2. Use the Toolset Types plugin to establish the relationships between your Post Types.
  3. Use the Toolset Views plugin to create relevant Content Templates and Views that will display the related posts.

You will find all the details in the new tutorials:

Give us your feedback

Using post relationship can be a powerful tool in your WordPress site development. What is your experience? Do you use post relationship in your sites?

Leave your comment and let’s start a conversation.

 

Comments 6 Responses

  1. These new tutorials are helpful. One thing that is missing (IMHO) from this functionality is the ability to effectively *delete* a parent object and have that delete cascade to its children.

    If I have say, a parent type of Customer Order, with child types of Product to represent someone buying a number of Products, If I delete the Order, I’m left with orphaned child Product posts that I have to somehow find and manually delete.

    I understand it’s a tricky problem to solve but I think you should at least point out the issue in your tutorials so that people are aware of it – while you work on a way to handle it :-).

    • Hi Tom,

      This Juan, Toolset lead developer here. Thanks a lot for your feedback. It makes a lot of sense. By now, when you delete a post on a parent post type, its children are left as “orphan”, in the sense that they do belong to the child post type but lack a parent.

      I am adding a feature request for this to our internal ticket system, so when you set the relationship you can also set what happens when deleting parents.

      Hope it helps.

      Regards.

    • The purpose of both plugins is the same: to create relationships between posts. However in Toolset you not only create relationships but you can build your custom templates and different designs based on posts connected in relationships, meaning you can display related post in various variations. You can even build custom front-end form based on posts connected in relationships.

      Posts 2 Posts is no longer actively developed. We are developing Toolset constantly.

      • You can check whether there is a Toolset following features:

        1) The relationship between the post of one custom type? For example, between individual news.
        2) Relationships. If the connection is listed in one post, it will automatically appear in the other.

        • Hi again,
          1) Yes, you can achieve it with Toolset. Types plugin allows you to make you Post Types hierarchical (the same what happens with WordPress regular Pages – you can set a Parent page). This is done in the Option section. Then you can use Views to display your posts.
          2) I’m not sure what exactly you mean here. Can you elaborate?