{"id":8264,"date":"2021-08-15T13:28:06","date_gmt":"2021-08-15T03:28:06","guid":{"rendered":"https:\/\/wpdevdesign.wpengine.com\/?p=8264"},"modified":"2022-02-22T12:22:25","modified_gmt":"2022-02-22T01:22:25","slug":"meta-box-relationship","status":"publish","type":"post","link":"https:\/\/wpdevdesign.com\/meta-box-relationship\/","title":{"rendered":"Meta Box Relationship"},"content":{"rendered":"<div class=\"mp_wrapper\">\n  <div class=\"mepr-unauthorized-excerpt\">\n    <p>This <a href=\"\/membership\/\">members-only<\/a> tutorial provides the steps to use <a href=\"\/go\/meta-box\/\" target=\"_blank\" rel=\"noreferrer noopener\">Meta Box<\/a> to set up a relationship between two custom post types, <code>portfolio<\/code> and <code>product<\/code> and output a list of portfolio items with the related products for each item as an unordered list.<\/p>\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-relationship-field.png\"><img src=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-relationship-field-1024x787.png\" alt=\"\" class=\"wp-image-8266\" \/><\/a><\/figure>\n<figure class=\"wp-block-image size-large\"><img src=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-related-cpts-output-1024x476.png\" alt=\"\" class=\"wp-image-8270\" \/><\/figure>\n<p>While the tutorial shows implementing this in <a href=\"https:\/\/oxygenbuilder.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oxygen<\/a>, it can be applied in any WordPress site.<\/p>\n<h2 class=\"wp-block-heading\" id=\"step-1\">Step 1<\/h2>\n<p>Install Meta Box and <a rel=\"noreferrer noopener\" href=\"https:\/\/metabox.io\/plugins\/mb-relationships\/\" target=\"_blank\">MB Relationships<\/a> extension or <a href=\"https:\/\/wpdevdesign.com\/go\/meta-box-aio\/\" target=\"_blank\" rel=\"noreferrer noopener\">Meta Box AIO<\/a>.<\/p>\n<p>Assuming that both the CPTs that you want to connect are already registered and have some items, create a new Relationship at Meta Box &gt; Relationships.<\/p>\n<p>Set the post types in the From and To sections.<\/p>\n<p>Note that the relationship is bi-directional out of the box (what's up ACF?) and \"Reciprocal relationship\" should not be ticked. That is for relationship between items of the same post type.<\/p>\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-relationship-backend.png\"><img src=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-relationship-backend-1024x758.png\" alt=\"\" class=\"wp-image-8267\" \/><\/a><\/figure>\n<h2 class=\"wp-block-heading\" id=\"step-2\">Step 2<\/h2>\n<p>Edit your portfolio items and assign the corresponding product(s) for each.<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img src=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/selecting-related-products-meta-box.png\" alt=\"\" class=\"wp-image-8268\" width=\"290\" height=\"359\" \/><\/figure>\n<h2 class=\"wp-block-heading\" id=\"step-3\">Step 3<\/h2>\n<p>In this tutorial we are going to output the portfolio CPT items with related products for each item on a static Page.<\/p>\n<p>Create your Page and edit it with Oxygen.<\/p>\n<p>Add a Section and a Code Block inside. Set its width to 100%.<\/p>\n<p>PHP &amp; HTML:<\/p>\n  <\/div>\n  <div class=\"mepr-unauthorized-message\">\n    <p>This is a premium members-only content.<\/p>\n<p>To view the rest of the content, please <a title=\"Membership\" href=\"https:\/\/wpdevdesign.com\/membership\/\">sign up for membership ($47\/month or $599 one-time)<\/a>.<\/p>\n<p>Already a member? Log in below or <a href=\"https:\/\/wpdevdesign.com\/login\/\">here<\/a>.<\/p>\n  <\/div>\n  <div class=\"mepr-login-form-wrap\">\n            \n<div class=\"mp_wrapper mp_login_form\">\n                  <!-- mp-login-form-start -->     <form name=\"mepr_loginform\" id=\"mepr_loginform\" class=\"mepr-form\" action=\"https:\/\/wpdevdesign.com\/login\/\" method=\"post\">\n            <div class=\"mp-form-row mepr_username\">\n        <div class=\"mp-form-label\">\n                              <label for=\"user_login\">Username<\/label>\n        <\/div>\n        <input type=\"text\" name=\"log\" id=\"user_login\" value=\"\" \/>\n      <\/div>\n      <div class=\"mp-form-row mepr_password\">\n        <div class=\"mp-form-label\">\n          <label for=\"user_pass\">Password<\/label>\n          <div class=\"mp-hide-pw\">\n            <input type=\"password\" name=\"pwd\" id=\"user_pass\" value=\"\" \/>\n            <button type=\"button\" class=\"button mp-hide-pw hide-if-no-js\" data-toggle=\"0\" aria-label=\"Show password\">\n              <span class=\"dashicons dashicons-visibility\" aria-hidden=\"true\"><\/span>\n            <\/button>\n          <\/div>\n        <\/div>\n      <\/div>\n            <div>\n        <label><input name=\"rememberme\" type=\"checkbox\" id=\"rememberme\" value=\"forever\" \/> Remember Me<\/label>\n      <\/div>\n      <div class=\"mp-spacer\">&nbsp;<\/div>\n      <div class=\"submit\">\n        <input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" class=\"button-primary mepr-share-button \" value=\"Log In\" \/>\n        <input type=\"hidden\" name=\"redirect_to\" value=\"\/wp-json\/wp\/v2\/posts\/8264\" \/>\n        <input type=\"hidden\" name=\"mepr_process_login_form\" value=\"true\" \/>\n        <input type=\"hidden\" name=\"mepr_is_login_page\" value=\"false\" \/>\n      <\/div>\n    <\/form>\n    <div class=\"mp-spacer\">&nbsp;<\/div>\n    <div class=\"mepr-login-actions\">\n        <a\n          href=\"https:\/\/wpdevdesign.com\/login\/?action=forgot_password\"\n          title=\"Click here to reset your password\"\n        >\n          Forgot Password        <\/a>\n    <\/div>\n\n      \n    <!-- mp-login-form-end --> \n  <\/div>\n      <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This members-only tutorial provides the steps to use Meta Box to set up a relationship between two custom post types, portfolio and product and output a list of portfolio items with the related products for each item as an unordered list. While the tutorial shows implementing this in Oxygen, it can be applied in any &hellip;<\/p>\n","protected":false},"author":1,"featured_media":8266,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"footnotes":""},"categories":[2,52,20],"tags":[302,182],"class_list":["post-8264","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-plugins","category-premium","category-wordpress","tag-meta-box","tag-relationship-field"],"acf":[],"featured_image_src":"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-relationship-field.png","featured_image_src_square":"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2021\/08\/meta-box-relationship-field.png","author_info":{"display_name":"Sridhar Katakam","author_link":"https:\/\/wpdevdesign.com\/author\/srikat\/"},"_links":{"self":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts\/8264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/comments?post=8264"}],"version-history":[{"count":0,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts\/8264\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/media\/8266"}],"wp:attachment":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/media?parent=8264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/categories?post=8264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/tags?post=8264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}