Relationships feature from Meta Box allows you to relate post types, users, pages together. In this practice, we’ll share the way to create a bi-directional relationship between Courses and Instructors post types for example. Then, we’ll display the related instructors to a course and vice versa, using Meta Box and Oxygen.

Create Relationships - Using Meta Box and Oxygen

Video Version

Before Getting Started

I have Courses and Instructors as two separate custom post types. I will create a bi-directional relationship between them. The relationship will show the course is contributed by which instructors and the instructor contributes to which courses. This kind of information will be displayed on the archive page and singular page of each post type.

As you can see, we’ll 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.

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

  • MB Custom Post Type: to create a custom post type for the courses and instructors.
  • Meta Box Builder: to have a UI on the backend to create custom fields and relationships easily.
  • MB Relationships: to create relationships between these post types.
  • MB Admin Columns: 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.

And the last one, I have Oxygen to build the pages. You should use its 3.9 version or higher, which has native integration with Meta Box.

Create the Custom Post Types

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

Create a new post type for the instructors

Then, you will see new menus displayed in the Admin Dashboard. They’re your post types.

There are the post types that we created

Create Custom Fields

You may want to add some custom fields for each post type for some extra information of the courses or the instructors. It’s optional. Just go to Meta Box > Custom Fields to create fields as usual. I also created some for the courses as follows.

Create custom fields for each post type for some extra information of the courses or the instructors

Create Relationships

Let’s create relationships between the Courses and Instructors post types. Go to Meta Box > Relationships to create a new one.

Create relationships between the Courses and Instructors post types

There’ll be the From and To section as follows. The relationship is bidirectional, so you can put the two post types into any section.

Setting relationships

Since they are post types, remember to set the object type as Post in both sections.

Set the object type as Post in both sections

Set the Post type in the From section as one that we want to be in the relationship. In this case I set Instructor, so the rest one in the To section will be the Course.

Set the Post type in the From section as one that we want to be in the relationship

Because I activated the MB Admin Column extension, I have this option in the relationship’s settings.

Show as an admin column

I set it to show the related courses and instructors in a column in the dashboard.

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

Set a label for the relationship section in the post editor.

That’s all to set the relationship. Go to a post editor of the Course post type, there’ll be a box at the right sidebar to choose which instructors related to the current post. As well as, there'll be a box in the post editor of the Instructor post type to choose which courses related to the current instructor. It displays as a field, this will make sense when you get posts from this field in the next step.

Choose which courses related to the current instructor

Then, in the dashboard, you will see the related posts like this:

The related posts

Display the Relationship

In this part, I will display these relations on both the singular page of the Course post type, and the Instructor post type, also on the archive page where all the courses are listed.

Display the Relationship on a Singular Page

Let’s display the relations on the singular page of the Course and the Instructor post types.

This is the page to show the detailed information about one instructor. There will be a section to show all the courses that the instructor contributed to.

The page to show the detailed information about one instructor

Go to Oxygen > Template > Add New Template as usual.

Go to Oxygen > Template > Add New Template

Remember to set the template as Singular and choose the name of the post type as Instructors and publish.

Set the template and choose the name of the post type

Then edit it with Oxygen.

Edit it with Oxygen

Choose an instructor for the preview.

Choose an instructor for the preview

Insert a Section component.

Insert a Section component

Add a Heading to display the name of the instructor from the post title.

Add a Heading to display the name of the instructor from the post title

Also add a Text component to display the biography of the instructor, that is saved in the post content.

Display the biography of the instructor

Now, let’s display the related courses. There will be multiple posts, so add a Repeater component.

Add a Repeater component

In its Query section, choose advanced and add parameters for the query like this.

Choose advanced and add parameters for the query

In there, course is the slug of the Courses post type. It means that we’ll get posts from this post type.

The slug of the Courses post type

Next, add the second parameter as follows.

Add the second parameter

To add the value in the parameter, choose Meta Box field from the range and we can see the Related Courses field that allows us to choose posts which are related to an instructor.

Choose posts which are related to an instructor

All of these parameters stipulate that only the posts that are listed in the Related Course field will be displayed.

All of these parameters stipulate are listed in the Related Course field

Inside the Repeater component, there’ll be a Div. Add some components inside this Div to display the courses’ information.

First, add an Image component and insert data from the Featured Image of the post.

Add an Image component and insert data from the Featured Image of the post

Add a Heading then insert data from the Post Title for the course name.

Add a Heading then insert data from the Post Title for the course name

You may get the wrong name and image of the course, but don't worry about it. Just keep moving, you will see the right things later.

Keep adding some other components, then insert data from custom fields of the Courses as usual. After getting all the wanted information for the course, save the template and go to the page on frontend. You will see the courses along with their information displayed correctly.

The courses along with their information displayed

Back to the template, the preview will display correctly as well. You can change the settings of each component to get the wanted look for the page. Here is the one that I got after styling.

The preview display correctly after styling

On the other hand, we also can display the instructor name in the singular page of the course. I already have a singular page with a template to display the course's detailed information. We’ll display the related instructor in this place.

Display the related instructor

Add a Div component or just duplicate one from your created Div components.

Add a Div component or just duplicate

Change the text in the Content section of the component.

Change the text in the Content section of the component

Then, insert data from the Related Instructor field into the component.

Insert data from the Related Instructor field into the component

If you want to display the instructor name along with the link, choose the Post URL option when inserting data like this.

Choose the Post URL option when inserting data

Then on the page that shows the course details, you will see the related instructor name as follows.

The course details on the page

Display the Relationship on an Archive Page

Let’s add related instructors to the archive page for the courses.

Add related instructors to the archive page for the courses

In the template of the page, you may have a Repeater element to display all the posts since this is an archive page.

Repeater element to display all the posts

Add a Div and some Text components inside the Repeater.

Add a Div and some Text components inside the Repeater

Change the content of the first Text component.

Change the content of the first Text component

Insert data from the Related Instructor field into the second Text component.

Insert data from the Related Instructor field into the second Text component

Save the template and we can see it displayed on the frontend.

The template displayed on the frontend

Last Words

The above was a very simple way to display the relationships in several typical places with Oxygen. You can display related content in any way with simple steps. If you have any concerns about it, let us know in the comments. Best of luck!

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 Custom 404 Page in WordPress - P1 - Using Meta Box and Elementor
  20. How to create a FAQs page - P5 - Using Meta Box and Breakdance
  21. How to Create a Product Page - P2 - Using Meta Box and Oxygen
  22. How to Create a Product Page - P3 - Using Meta Box and Bricks
  23. How to Create a Product Page - P4 - Using Meta Box and Elementor
  24. How to Create a Product Page - P5 - Using Meta Box and Gutenberg
  25. How to Create a Product Page - P6 -Using Meta Box and Breakdance
  26. How to Create a Product Page - P7 - Using Meta Box + Kadence
  27. How to Create a Product Page - P8 - Using Meta Box and Brizy
  28. How to Create a Product Page - P9 - Using Meta Box and Divi
  29. How to Create a Product Page using Meta Box Plugin
  30. How to Create a Recipe - P2 - Using Meta Box and Oxygen
  31. How to Create a Recipe - P3 - Using Meta Box and Elementor
  32. How to Create a Recipe - P4 - Using Meta Box and Bricks
  33. How to Create a Recipe - P5 - Using Meta Box and Zion
  34. How to Create a Recipe - P6 - Using Meta Box and Brizy
  35. How to Create a Recipe - P7 - Using Meta Box and Breakdance
  36. How to Create a Recipe - P8 - Using Meta Box and Kadence
  37. How to Create a Recipe - P9 - Using Meta Box and Divi
  38. How to Create a Recipe with Meta Box Plugin
  39. How to Create a Simple Listing - P2 - Using Meta Box and Bricks
  40. How to Create a Simple Listing - P3 - Using Meta Box and Breakdance
  41. How to Create a Simple Listing - P4 - Using Meta Box and Elementor
  42. How to Create a Team Members Page - P1- Using Meta Box and Elementor
  43. How to Create a Team Members Page - P2 - Using Meta Box and Oxygen
  44. How to Create a Team Members Page - P3 - Using Meta Box and Bricks
  45. How to Create a Team Members Page - P4 - Just Meta Box
  46. How to Create a Team Members Page - P6 - using Meta Box and Breakdance
  47. How to Create a Team Members Page - P7 - Using Meta Box and Kadence
  48. How to Create a Video Gallery Page - P2 - Using Meta Box + Bricks
  49. How to Create a Video Gallery Page - P3 - Using Meta Box and Breakdance
  50. How to Create a Video Gallery Page - P4 - Using Meta Box + Elementor
  51. How to Create a Video Gallery Page - P5 - Using MB Views
  52. How to Create a Video Gallery Page - P6 - Using Meta Box and Zion
  53. How to Create a Video Gallery Page Using Meta Box + Oxygen
  54. How to Create ACF Flexible Content Field with Meta Box
  55. How to Create an Auto-Updated Cheat Sheet in WordPress
  56. How to Create an FAQs Page - P1 - Using Meta Box and Elementor
  57. How to create an FAQs page - P2 - Using Meta Box and Oxygen
  58. How to create an FAQs page - P4 - Using Meta Box and Bricks
  59. How to Create an FAQs Page - P6 - Using MB Views
  60. How to Create an FAQs Page - P7 - Using Meta Box and Divi
  61. How to Create an FAQs Page - P8 - Using Meta Box and Kadence
  62. How to Create an FAQs Page - P9 - Using MB Blocks
  63. How to Create an FAQs Page -P3- Using Meta Box
  64. How to Create Buttons with Dynamic Link using Custom Fields
  65. How to Create Category Thumbnails & Featured Images Using Custom Fields
  66. How to Create Download and Preview Buttons - P1 - Using Meta Box and Bricks
  67. How to Create Download and Preview Buttons - P2 - Using Meta Box and Oxygen
  68. How to Create Download and Preview Buttons - P3 - Using MB Views
  69. How to Create Download Buttons in WordPress - Using Custom Fields
  70. How to Create Dynamic Landing Page in WordPress - P1 - Using Meta Box and Elementor
  71. How to Create Dynamic Landing Page in WordPress - P2 - Using Meta Box and Bricks
  72. How to Create Menus for Restaurants - P1 - Using Meta Box and Elementor
  73. How to Create Menus for Restaurants - P2- Using Meta Box and Bricks
  74. How to Create Notification Using Custom HTML Field
  75. How to Create Online Admission Form for School or University
  76. How to Create Online Reservation Form for Restaurants using Meta Box
  77. How to Create Relationships - P1 - Using Meta Box and Oxygen
  78. How to Create Relationships - P2 - Using Meta Box and Bricks
  79. How to Create Relationships - P3 - Using MB Views
  80. How to Create Relationships - P4 - Using Meta Box and Breakdance
  81. How to Create Taxonomy Thumbnails & Featured Images - P2 - Using Meta Box and Oxygen
  82. How to Create Taxonomy Thumbnails & Featured Images - P3 - Using Meta Box and Bricks
  83. How to Create Taxonomy Thumbnails & Featured Images - P4 - Using MB Views
  84. How to Create YouTube Video Timestamps on WordPress Website - P1 - Using MB Views
  85. How To Display All Listings On A Map With Meta Box
  86. How to Display Author Bio in WordPress - P1 - Using Meta Box and Bricks
  87. How to Display Author Bio in WordPress - P2 - Using MB Views
  88. How to Display Dynamic Banners in WordPress - P3 - Using MB Views
  89. How to Display Images from Cloneable Fields - P1 - with Gutenberg
  90. How to Display Images from Cloneable Fields - P2 - Using Meta Box and Oxygen
  91. How to Display Images from Cloneable Fields - P3 - with Elementor
  92. How to Display Images from Cloneable Fields - P4 - with Bricks
  93. How to Display Opening Hours for Restaurants - P1 - Using Meta Box + Gutenberg
  94. How to Display Opening Hours for Restaurants - P2 - Using Meta Box and Oxygen
  95. How to Display Product Variations - P1 - Using Meta Box and Gutenberg
  96. How to Display Product Variations - P2 - Using Meta Box and Oxygen
  97. How to Display Product Variations - P3 - Using Meta Box and Bricks
  98. How to Display the Dynamic Banners - P2 - Using Meta Box and Bricks
  99. How to Display The Latest Products - P5 - Using Meta Box and Bricks

6 thoughts on “How to Create Relationships - P1 - Using Meta Box and Oxygen

  1. Trying to follow this step by step, when I get to "To add the value in the parameter, choose Meta Box field from the range and we can see the Related Courses field that allows us to choose posts which are related to an instructor.", I do not have the relationships button in the meta box field options?
    Any ideas what I'm doing wrong?
    Thanks
    Dan

    1. I guess that you didn't set the labels when you create the relationship, back to that step, then go to the Field tab in the relationship settings to add the labels. When adding the parameter, look for the field with label you added. Try it and let us know the result!

  2. Hello,

    In the last step (Archive page).
    I would like to show the title of a related post but without the link.
    Is it possible ?

    Thanks you !

    Regards,

  3. Hello,

    I have another problem.
    Imagine courses have multiple instructors.

    I want to show all instructor. When I make the custom query like you in this article, I only have one instructor who appears.

    Can you explain me how I can do ?

    Thanks,

Leave a Reply

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