3 Non-Obvious Applications of Post Relationships in WordPress

February 21, 2022

Toolset provides the most robust way of connecting post types using relationships in WordPress. Some obvious applications of post relationships are cross-connecting events and speakers or cars and manufacturers. We present 3 less obvious applications of cross-connecting posts to get you inspired with other practical usages. 

If you’re new to Toolset post relationships, check out our introduction to what post relationships are and how they work or read through the whole section about using post relationships – videos included.

Let’s dive in and see how to use post relationships in diverse ways. And remember, these are only examples, you can use post relationships on any kind of content. You can also connect the same post type to multiple others or have multiple relationships between the same ones.

You can use regular WordPress pages as documentation for your product and then connect these pages to a custom post type that tells more about the product.

This is what we did for our theme compatibility pages for WPML. The following image shows a page with compatibility information between WPML and Divi:

A page on WPML.org displaying compatibility information between WPML and Divi

We use a custom post type for “Certified Themes” and regular Pages for documentation on how to use themes with WPML. In the example above, you can see the Divi theme and the highlighted link to the documentation page. 

We have created a relationship between Pages and “Certified Themes”to cross-connect these two post types:

Connecting “Certified themes” and “Pages” post types using a many-to-many relationship

To display a list of related documentation pages we created a View and inserted it into the custom template for displaying single Certified Themes posts.

How-To Steps

  1. Use regular WordPress Pages for your documentation.
  2. Create a custom post type for “Certified themes”.
  3. Go to ToolsetRelationships and create a many-to-many relationship between Pages and Certified themes.
  4. Edit the theme pages and connect them with corresponding documentation pages.
  5. Create a custom template for single-theme pages.
  6. In the template, display the content of your theme post and its custom fields.
  7. To display related documentation pages, you need to create a View. Because you are inserting the View inside a template for a specific post type, Toolset already has the information about related post types. It will allow you to easily display a list of connected pages.

Please note that you can create other post relationships for the same post type. Our example also displays a list of known issues for the current theme:

Compatibility page displaying related “Known Issues” posts

“Known issues” is another post type. We have created a relationship between Known issues and Certified themes post types. 

Next, we edited our template for displaying single Certified theme posts and inserted another View into it. This View lists Known issues posts for a given theme.

#2 Displaying Outfits for WooCommerce Products

You can also connect custom post types with WooCommerce Products through relationships. For example, you could create the “Outfit” custom post type and connect specific outfits with relevant products to buy: 

A single Outfit post displaying related WooCommerce products

How-To Steps

  1. Create the “Outfit” post type.
  2. Go to ToolsetRelationships and create a many-to-many relationship between Outfits and WooCommerce Products.
  3. Edit your Outfit posts and connect them with corresponding products.
  4. Create a custom template for displaying Outfit posts.
  5. To display a list of related products, insert the View block into your template for Outfits. When setting up the View, choose for it to display Products. Toolset will return all related outfits for a given product.

But you can also do it the other way around. You can create a custom template for products and display related outfits.

A single-product page displaying a list of related outfit posts

#3 Displaying 3rd-party Gallery Blocks Inside Single-post Templates

Nowadays, many block plugins offer beautiful blocks for displaying gallery images. The Advanced Gallery block from Kadence is a great example.

You might want to use these galleries inside your custom templates for single posts. In our example, we have a custom post type for “Tutors” and its content has a “Gallery” tab:

Tutor page (based on a Content Template) using the Kadence Advanced Gallery block.

Here’s the same “Gallery” tab but this time, it uses a slider mode for the gallery images.

Another Tutor page using the Advanced Gallery block – same single-post template but different gallery option

The challenge here is that there is no integration between Toolset custom fields and the 3rd-party gallery blocks. No worries – this is where using a one-to-one post relationship comes to the rescue.  

How-To Steps

  1. Create a post type for the content you need. In our case, it was Tutors.
  2. Create another post type, called Galleries. This extra post type will act as a container for your 3rd-party gallery block. 
  3. Next, create a one-to-one relationship between these two post types.
Connecting Tutors and Galleries post types using a one-to-one relationship
  1. Now, when editing a Tutor post you can connect a Gallery post to it, like this:
A related gallery post at the bottom of the Tutor post editing screen
  1. As the “Galleries” is a separate post type, you can click to create a new gallery post connected to the current Tutor. This will open an editor for creating a new gallery post. Then, insert the Kadence Advanced Gallery block into the editor:
Kadence Advanced Gallery block used inside a connected gallery post

We have also added a custom field to our Gallery post type that represents the gallery cover image. This is optional but can come in handy when displaying a list of all galleries.

To display the gallery inside your Content Template for tutors, you need to use the Toolset Single field block set to the Gallery post and the Post Content (body):

Displaying the content of the related post using the Toolset Single Field block

And that’s it! Now, our single Tutor posts display their image gallery using a fancy 3rd-party block, all thanks to a simple one-to-one post relationship.

There’s More!

This article is part of an ongoing series where we present interesting and powerful ideas of what you can build with Toolset. We’re publishing these every few weeks, so stay tuned!

Other articles in this series:

Feedback? Suggestions?

Do you use post relationships on the websites you build? What’s your favorite usage of post relationships? Have any tips to share?

Share your thoughts with everyone in the comments!

 

Comments 12 Responses

  1. Interesting article.

    I am building a site which is extensively based on one-to-many and many-to-many post relationships. It is also using a single CPT to several CPT post relationships and vice-versa. In fact, the entire site is based on post relationships.

    Initially, everything was very confusing but with the help of support and playing around, I was finally able to get to the bottom of this.

    It is actually very easy if the basic concepts are clear. So I had spent a lot of time on studying examples, documentations etc.

    However, what made it easier to work with post relationships was Toolset Blocks. Earlier, I was finding blocks very difficult to use, but when I started working with Toolset Blocks, I realized how easy it was to design layouts using blocks. And then I also learned about Kadence Blocks, which adds even more charm and design possibilities.

    So with the help of Toolset, I was able to accomplish many things that otherwise would have taken countless hours, trial & errors, debugging and thereafter, maintaining the code to make sure it is always up-to-date with the latest versions of PHP & WordPress.

    • Hello Alok, we are glad to hear that you find blocks and relationships useful. Yes, using relationships with blocks is easier compared to using post relationships with the shortcode-based version of Toolset Views (which we consider legacy now but we know that many Toolset clients still use them when they need HTML/CSS granularity). Thank you for your comment and kind words.

  2. Good examples.

    Trying to explain it to people makes eyes glaze over because it’s definitely next level and most people get stuck on categories and tags. I had ignored them for a while myself but found a project where Taxonomy alone couldn’t do the job.

    Relationships turned out to be a MASSIVELY HELPFUL for me as I wasn’t going to settle for redundancy (opening me up to mismatched info) and needed something flexible, but also easy-to-use.

    This was it.

    My go to example for people is Movies and Actors. I don’t think sane people would make Movies (ex “The Avengers”) a taxonomy, but instead a Custom Post Type. Actors would also be a Custom Post Type (ex “Samuel L. Jackson”). Just as a Movie can feature many actors, an Actor can appear in many movies. The ability to loop the data of multiple Actors into a Movie post template and the data of multiple Movies into an Actors post template is huge.

    Actor Parent Page would loop Movie Child Fields like movie title, release date, domestic gross…

    Samuel L. Jackson:
    Pulp Fiction – 1994 – $40million
    Snakes on Plane – 2006 – $100million
    The Avengers – 2012 – $100gagillion

    And likewise…

    Movie Parent Page would loop Actor Child Fields like actor name, age, known for

    Pulp Fiction:
    Samuel L. Jackson – 76 – Known For The Avengers
    John Travolta – 67 – Known For Saturday Night Fever
    Uma Thurman – 50 – Known For Kill Bill

    • Yes, your example with Actors and Movies is great. I’m glad you find Toolset relationship features useful.

  3. This article is fantastic. I wrote to support a few days ago about the design limitations of the Toolset Slider and Gallery blocks. I wanted to use the Kadence gallery/slider block which has auto and timed transitions etc, but could not pull multiple images from my custom post type. This is the solution to my problem! Awesome, thanks so much.

  4. I have a couple of questions
    1. You say “We have also added a custom field to our Gallery post type that represents the gallery cover image” is this a field that displays the first gallery image automatically? If so how? Or is it just a media field where you add an image to represent the gallery?
    2. I am trying to use this with the Hbook plugin which has a custom post type “Accommodation”. I created “Room Gallery” post type. Connected them one to one. Added a Room gallery post with a Kadence gallery. When I go to An Accommodation post and add connect the room gallery it is fine. Then when I insert the Toolset single field block I select Child:Room galleries for Post Source BUT Post Field stangely displays Post Title, Post Slug and many more BUT NOT Post Content(Body)
    Do you have any idea what is wrong?

    • Hello Gason,
      1. Not, it won’t happen fully automatically. First, you need to open a post for editing and pick the image you want to be stored in that field. Then, you can access this field from your Content Template for that post type or for Content Template from the related post.
      2. Please make sure you do it from within the Content Template for the post (Accommodation), not directly from within the actual post body. I’ve updated the tutorial to make it clear.

  5. OK I have investigated a bit more …
    Selecting Child:Room Galleries does not work.
    But I discovered that the Post Source drop down lists the Room Gallery posts specifically by name. “Mini apartment with kitchenette gallery”
    When that is selected Post Field shows Post Content (Body)
    Select that and it works as per the tutorial.

    • I’m glad you found a workaround. I have just tested the steps in the tutorial and they also work provided you use the Single field block in your Content Template. Make sure to save the Content Template first. I recall an issue of the post content body not appearing until you save the Content Template.

  6. Thanks Agnes.
    My problem was I was, as you thought, that I was not accessing it from a Template. Thanks for updating the article and your responses. It works fine from the Template 🙂 and yes you recall correctly body does not appear until after saving the template.