Continuing the series on creating a relationship between two objects on your website, we have just explored a different method, using Meta Box and Breakdance. In this practice, we’ll create a bi-directional relationship between Courses and Instructors post types and show them on both singular and archive pages.

This is an archive page for example. It includes a list of courses and the name of instructors who contributed to each course.

This is an archive page

This is a singular page that shows information of an Instructor. There is also a section to display all the courses contributed by this instructor.

This is a singular page that shows information of an Instructor

Video Version

Before Getting Started

We have two separate custom post types: Courses and Instructors. In this case, the relationship is to link the courses to their instructors, and also link each instructor to the courses to which they contributed. This bi-directional relationship will be shown on the both singular page of each post type and the archive page for Courses.

So, we need the Meta Box core plugin to have a framework to create custom post types, custom fields, and relationships. You can download it directly from wordpress.org.

Moreover, we need some Meta Box extensions for the advanced features:

  • MB Custom Post Type: to create custom post types for the courses and instructors;
  • MB Relationships: to create relationships between these post types;
  • Meta Box Builder: to have an intuitive UI on the backend to create custom fields and relationships;
  • MB Admin Columns (optional): to display the related courses and related instructors in the dashboard.

You can install these extensions individually or use Meta Box AIO to have them all.

The last one is Breakdance to build the pages.

Create the Custom Post Types

Go to Meta Box > Post Types to create a new post type for the instructors, and another one for courses.

Go to Meta Box > Post Types to create new post types for Instructors and Courses

After publishing, you will see new menus displayed. These are my created post types.

These are created post types

Create Custom Fields

If you want to add some custom fields to save some extra information for each post type, just go to Meta Box > Custom Fields to create fields as usual. In this practice, I just add some fields for the courses.

Go to Meta Box > Custom Fields to create fields for the Courses

After creating all the wanted fields, go to the Settings tab, set the Location as Post type, and select the post type you want to apply the fields to.

Go to the Settings tab, set the Location as Post type, and select the post type you want to apply the fields

Create Relationships

Go to Meta Box > Relationships to create the relationships between the Courses and Instructors post types.

Go to Meta Box > Relationships to create the relationships between the Courses and Instructors

There’ll be two sections: From and To with the same structure of settings.

There’ll be two sections: From and To with the same structure of settings

Because we’re setting the relationship between 2 post types, set the Object Type as Post in both two sections.

set the Object Type as Post in both two sections.

In the Post type option, choose the post type you want to create a relationship. The relationship is bi-directional, so you can put the post types not in order. For example, I set the Instructor in the From section, and the rest is Course.

Set the Instructor in the From section, and the rest is Course.

Because I activated the MB Admin Columns extension before, I have the following option in both two sections of the relationship’s settings.

Set Admin Colums for two sections of the relationship’s settings.

It will help to display the related posts from the relationship on the dashboard like this.

the related posts from the relationship displayed on the dashboard

In the Field tab, you can set the label for the relationship section in the post editor.

In the Field tab, you can set the label for the relationship section in the post editor.

After publishing the relationship, you will see a new field on the right sidebar in the post editor of each post type.

In the post editor of the Course post type, you will see this one to choose which instructor is related to the current post. You can select several instructors in this section.

Select several instructors in the post editor of the Course post type

It’ll be the same when you add related courses for an instructor.

add related courses for an instructor

In the dashboard, add related courses for an instructor like this.

In the dashboard, add related courses for an instructor like this

Create a Global Block for Courses

I will create a section to show all the information of the courses that the instructor contributed to. To display information about each course, we should create a global block.

create a global block to show all the information of the courses that the instructor contributed to

Go to Breakdance > Global Blocks.

Go to Breakdance > Global Blocks.

Select Div element to cover the whole block.

Select Div element to cover the whole block.

Add an Image element to show the course image.

Add an Image element to show the course image.

Click on the Insert Dynamic Data button to insert dynamic data to this element.

Click on the Insert Dynamic Data button to insert dynamic data to this element.

Then choose Featured Image in the Post section.

choose Featured Image in the Post section.

The name of the course is the post title and embedded link, so add the Text Link element.

Add the Text Link element for the name of the course

Then insert dynamic data from the Post Title.

insert dynamic data from the Post Title.

The Text Link element also provides a setting to set the embed link as dynamic data.

The Text Link element provides a setting to set the embed link as dynamic data.

And choose Post Permalink inside.

choose Post Permalink inside.

I’ll add a Div element for each kind of information that is from custom fields.

Add a Div element for each kind of information

Go ahead, add a Text element for showing the first course’s information.

Add a Text element for showing the first course’s information.

This course’s information is saved in a custom field created with Meta Box, so also insert dynamic data to the Text element. Look for the Metabox section, choose the name of the custom field.

Insert dynamic data to the Text element. In the Metabox section, choose the name of the custom field.

For other lines, in the same way, just duplicate this Div element, change each Text element inside to get the right name and data from custom fields.

Duplicate Div element, change each Text element inside to get the right name and data from custom fields.

You can change those elements to style this block a little bit to have a good look.

Style the block a little bit to have a good look.

Display the Relationship

In this practice, we’ll display this relationship on the singular page of the Instructor post type; and on the archive page where all the courses are listed.

Display the Relationship on the Singular Page of Instructors

This is an example of the Instructor post type. It shows detailed information about one instructor. There will be a section to show all the courses that the instructor contributed to. and, we already have a global block to display each one of those posts.

This is an example of the Instructor post type

Go to Breakdance and create a new template for the page.

Go to Breakdance and create a new template for the page.

Remember to set the location for this template as the single page of the Instructors post type.

Remember to set the location for this template as the single page of the Instructors post type.

Add a Section element to cover all the content of the page.

Add a Section element to cover all the content of the page.

Add the Post Title element to display the instructor name.

Add the Post Title element to display the instructor name.

Then, add the Post Content element to get the instructor’s description.

Add the Post Content element to get the instructor’s description.

For the section displaying all the contributed courses, there are multiple posts so we should add the Post Loop Builder element.

Add the Post Loop Builder element to display all the contributed courses

Choose the name of the created global block.

Choose the name of the created global block.

Since we haven’t set the source of data to query from, there will be no information display.

Since we haven’t set the source of data to query from, there will be no information display.

To display the course’s information, move to the Query section of the Post Loop Builder element, choose Array.

Move to the Query section of the Post Loop Builder element, choose Array to display the course’s information,

We should add some lines of code like this:

return [
'post_type' => 'course',
'posts_per_page'=>-1,
'relationship' => [
'id' => 'instructor-to-course',
'from' => get_the_ID()
],
];

add some lines of code

'post_type' => 'course',

This line code is to stipulate that we will query posts from the Course post type.

'relationship' => [
'id' => 'instructor-to-course',
'from' => get_the_ID()
],

These lines are to stipulate that only the posts that are set in the relationship will be queried. instructor-to-course is the ID of the created relationship.

After adding the query, you will see a list of courses displayed automatically.

A list of courses displayed automatically after adding the query

Just style this template now to get a better display.

Style this template to get a better display.

Display the Relationship on an Archive Page

We’ll create an archive page showing all the courses. There will be the same kind of information for each course should be displayed, so you should create a global block for them.

This is an archive page showing all the courses

In that global block, I also display the related instructor names of the course.

This is a page show the related instructor names of the course.

There may be more than one instructor contributing to a course, so we should use a global block to get and display their names.

So, there will be two new global blocks:

There are two new global blocks

Display the Instructor’s name

Instructor Block is to display the instructor name only, so add a Text link element.

Add a Text link element to display the instructor name

Click on the Insert Dynamic Data button to insert dynamic data from the Post Title. Insert link as well from the Post Permalink.

Click on the Insert Dynamic Data button to insert dynamic data from the Post Title. Insert link as well from the Post Permalink.

Next, we will add the instructor name from the created global block to the block for displaying course information.

This block to display the course on the archive page has the same structure and content with the one for the course on the Instructor singular page, so just copy all the elements from the previous block, and paste to this new one.

Copy all the elements from the previous block, and paste to this new one.

In the new global block for the courses, I’ll add a new Div element to display the instructor's name. Or, just duplicate the Div element to inherit its style then change the text.

Add a new Div element to display the instructor's name

Add the Post Loop Builder element inside the new Div.

Add the Post Loop Builder element inside the new Div.

Choose the global block as the one we created for the instructor.

Choose the global block as the one we created for the instructor.

We also need to regulate the query for this element. Choose Array, and add code.

Choose Array, and add code to regulate the query for the element.

return [
'post_type' => 'instructor',
'posts_per_page'=>-1,
'relationship' => [
'id' => 'instructor-to-course',
'from' => get_the_ID()
],
];

These lines are the same with the one we use to display the related course in the previous step. Just replace the ID of the post type with the instructor.

This preview post has names of two instructors, so we should style this global block a bit more.

This preview post has names of two instructors

Now, it looks like this.

The instructor names after styling.

Create the archive page

Now, go to create the archive page then edit it in Breakdance.

go to create the archive page then edit it in Breakdance.

Add a Section element to cover the page.

Add a Section element to cover the page.

Inside the section, add the Heading element to the page title.

Inside the section, add the Heading element to the page title.

For the list of courses, use the Post Loop Builder again. Set the global block as Course Archive Block that we use for the courses displaying on this archive page.

Use the Post Loop Builder and set the global block as Course Archive Block that using for the courses

And set the query for it. Just replace the post type with course.

Set the query for it. Just replace the post type with 'course'.

Now, customize the layout. Then you will have the best archive page.

This is the final look I have after styling

We’ve finished.

Last Words

It's easy to create a relationship by using Meta Box and Breakdance. Furthermore, Breakdance supports creating related contents in an effortless way. So, let’s give it a try and share the results with us.

Hopefully, this tutorial will make sense to you. If you are looking for creating a relationship with another page builder, please look for it in this series.

If you have any suggestions for future tutorials, feel free to leave a comment below. Thanks for reading!

Other case studies you might be interested in

  1. Create A Dynamic Landing Page in WordPress Using Custom Field
  2. Create a Filter to Find Hotels by Location
  3. Create an OTA Website Like Booking.com with Meta Box Plugin - P1: Create a Page to Introduce Hotel Rooms
  4. Create an OTA Website Like Booking.com with Meta Box Plugin - P2: Create Filters on the Archive Page
  5. Create an OTA Website Like Booking.com with Meta Box Plugin - P3: Create Filters for Single Hotel Pages
  6. Create Dynamic Favicon in WordPress using Meta Box plugin
  7. Create Posts Series in WordPress Using Meta Box
  8. Display The Latest Products Section - P2 - Using Meta Box and Elementor
  9. Display The Latest Products Section - P3 - Using Meta Box And Oxygen
  10. How to Add Custom Fields for WooCommerce - P2 - Using MB Views
  11. How to Add Custom Fields to Display Banners using Meta Box Plugin
  12. How to Add Guest Authors and Guest Posts - Using Meta Box
  13. How to Add Related Posts - Using Custom Fields
  14. How to Build a Hotel Booking Website Using Meta Box - P1
  15. How to Build a Hotel Booking Website Using Meta Box - P2 - Booking Page in Backend
  16. How to Build a Hotel Booking Website Using Meta Box - P4 - Booking Management Page
  17. How to Build a Hotel Booking Website Using Meta Box – P3 – Booking Page for Customer
  18. How to Create a Classified Ads Website using Meta Box
  19. How to create a FAQs page - P5 - Using Meta Box and Breakdance
  20. How to Create a Product Page - P2 - Using Meta Box and Oxygen
  21. How to Create a Product Page - P3 - Using Meta Box and Bricks
  22. How to Create a Product Page - P4 - Using Meta Box and Elementor
  23. How to Create a Product Page - P5 - Using Meta Box and Gutenberg
  24. How to Create a Product Page - P6 -Using Meta Box and Breakdance
  25. How to Create a Product Page - P7 - Using Meta Box + Kadence
  26. How to Create a Product Page - P8 - Using Meta Box and Brizy
  27. How to Create a Product Page - P9 - Using Meta Box and Divi
  28. How to Create a Product Page using Meta Box Plugin
  29. How to Create a Recipe - P2 - Using Meta Box and Oxygen
  30. How to Create a Recipe - P3 - Using Meta Box and Elementor
  31. How to Create a Recipe - P4 - Using Meta Box and Bricks
  32. How to Create a Recipe - P5 - Using Meta Box and Zion
  33. How to Create a Recipe - P6 - Using Meta Box and Brizy
  34. How to Create a Recipe - P7 - Using Meta Box and Breakdance
  35. How to Create a Recipe - P8 - Using Meta Box and Kadence
  36. How to Create a Recipe - P9 - Using Meta Box and Divi
  37. How to Create a Recipe with Meta Box Plugin
  38. How to Create a Simple Listing - P2 - Using Meta Box and Bricks
  39. How to Create a Simple Listing - P3 - Using Meta Box and Breakdance
  40. How to Create a Simple Listing - P4 - Using Meta Box and Elementor
  41. How to Create a Team Members Page - P1- Using Meta Box and Elementor
  42. How to Create a Team Members Page - P2 - Using Meta Box and Oxygen
  43. How to Create a Team Members Page - P3 - Using Meta Box and Bricks
  44. How to Create a Team Members Page - P4 - Just Meta Box
  45. How to Create a Team Members Page - P6 - using Meta Box and Breakdance
  46. How to Create a Team Members Page - P7 - Using Meta Box and Kadence
  47. How to Create a Video Gallery Page - P2 - Using Meta Box + Bricks
  48. How to Create a Video Gallery Page - P3 - Using Meta Box and Breakdance
  49. How to Create a Video Gallery Page - P4 - Using Meta Box + Elementor
  50. How to Create a Video Gallery Page - P5 - Using MB Views
  51. How to Create a Video Gallery Page - P6 - Using Meta Box and Zion
  52. How to Create a Video Gallery Page Using Meta Box + Oxygen
  53. How to Create ACF Flexible Content Field with Meta Box
  54. How to Create an Auto-Updated Cheat Sheet in WordPress
  55. How to Create an FAQs Page - P1 - Using Meta Box and Elementor
  56. How to create an FAQs page - P2 - Using Meta Box and Oxygen
  57. How to create an FAQs page - P4 - Using Meta Box and Bricks
  58. How to Create an FAQs Page - P6 - Using MB Views
  59. How to Create an FAQs Page - P7 - Using Meta Box and Divi
  60. How to Create an FAQs Page -P3- Using Meta Box
  61. How to Create Buttons with Dynamic Link using Custom Fields
  62. How to Create Category Thumbnails & Featured Images Using Custom Fields
  63. How to Create Download and Preview Buttons - P1 - Using Meta Box and Bricks
  64. How to Create Download and Preview Buttons - P2 - Using Meta Box and Oxygen
  65. How to Create Download and Preview Buttons - P3 - Using MB Views
  66. How to Create Download Buttons in WordPress - Using Custom Fields
  67. How to Create Dynamic Landing Page in WordPress - P1 - Using Meta Box and Elementor
  68. How to Create Dynamic Landing Page in WordPress - P2 - Using Meta Box and Bricks
  69. How to Create Menus for Restaurants - P1 - Using Meta Box and Elementor
  70. How to Create Menus for Restaurants - P2- Using Meta Box and Bricks
  71. How to Create Notification Using Custom HTML Field
  72. How to Create Online Admission Form for School or University
  73. How to Create Online Reservation Form for Restaurants using Meta Box
  74. How to Create Relationships - P1 - Using Meta Box and Oxygen
  75. How to Create Relationships - P2 - Using Meta Box and Bricks
  76. How to Create Relationships - P3 - Using MB Views
  77. How to Create Relationships - P4 - Using Meta Box and Breakdance
  78. How to Create Taxonomy Thumbnails & Featured Images - P2 - Using Meta Box and Oxygen
  79. How to Create Taxonomy Thumbnails & Featured Images - P3 - Using Meta Box and Bricks
  80. How to Create Taxonomy Thumbnails & Featured Images - P4 - Using MB Views
  81. How to Create YouTube Video Timestamps on WordPress Website - P1 - Using MB Views
  82. How To Display All Listings On A Map With Meta Box
  83. How to Display Author Bio in WordPress - P1 - Using Meta Box and Bricks
  84. How to Display Images from Cloneable Fields - P1 - with Gutenberg
  85. How to Display Images from Cloneable Fields - P2 - Using Meta Box and Oxygen
  86. How to Display Images from Cloneable Fields - P3 - with Elementor
  87. How to Display Images from Cloneable Fields - P4 - with Bricks
  88. How to Display Opening Hours for Restaurants - P1 - Using Meta Box + Gutenberg
  89. How to Display Opening Hours for Restaurants - P2 - Using Meta Box and Oxygen
  90. How to Display Product Variations - P1 - Using Meta Box and Gutenberg
  91. How to Display Product Variations - P2 - Using Meta Box and Oxygen
  92. How to Display Product Variations - P3 - Using Meta Box and Bricks
  93. How to Display the Dynamic Banners - P2 - Using Meta Box and Bricks
  94. How to Display The Latest Products - P5 - Using Meta Box and Bricks
  95. How to Display the Latest Products - P6 - using Meta Box and Breakdance
  96. How to Display the Latest Products - P7 - Using Meta Box + Kadence
  97. How to Display the Latest Products Section - P4 - Using Meta Box + Zion
  98. How to Display the Most Viewed Posts - P1 - using MB Views
  99. How to Display the Most Viewed Posts - P2 - using Meta Box and Oxygen

Leave a Reply

Your email address will not be published. Required fields are marked *