{"id":1624449,"date":"2020-05-14T14:39:39","date_gmt":"2020-05-14T14:39:39","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1624449"},"modified":"2020-12-09T12:59:12","modified_gmt":"2020-12-09T12:59:12","slug":"creating-and-displaying-repeatable-field-groups","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/fr\/course-lesson\/creating-and-displaying-repeatable-field-groups\/","title":{"rendered":"Creating and Displaying Repeatable Field Groups"},"content":{"rendered":"\n<p>The best way to understand what Repeatable Field Groups are and how to use, is via an example. We\u2019ll look at a <strong>gyms directory site<\/strong>. Each gym has a section about opening hours. Because opening hours are different for each gym we can add them as a repeatable group of <a href=\"https:\/\/toolset.com\/fr\/glossary\/custom-fields\/\">custom fields<\/a>.<\/p>\n\n\n\n<p>In our repeatable group, we can repeat days and each day can have a field for the day\u2019s name and day\u2019s opening hours.<\/p>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid tb-grid\" data-toolset-blocks-grid=\"3d9c399fe625e1b972f817a0680229f6\">\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\"><div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"cfc7060ea56f3f53a2285eb8f03159ce\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-groups-when-editing-a-post.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-groups-when-editing-a-post-500x491.png\" alt=\"Repeatable field groups when editing a post\" class=\"wp-image-1381065\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Repeatable field group when editing a post<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<figure class=\"wp-block-image tb-image tb-image-media\" data-toolset-blocks-image=\"6458b295d868e068f53a51b713d5d98d\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end.png\"><img decoding=\"async\" width=\"1197\" height=\"895\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end.png\" alt=\"Gym opening hours displayed on the front-end using a repeatable field group\" class=\"wp-image-1381265\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end.png 1197w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end-150x112.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end-300x224.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end-768x574.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end-1024x766.png 1024w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end-695x520.png 695w\" sizes=\"auto, (max-width: 1197px) 100vw, 1197px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Repeatable field group on the front-end<\/figcaption><\/div><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-repeatable-field-groups\">Creating Repeatable Field Groups<\/h2>\n\n\n\n<p>Follow these steps to add a repeatable field group to a post-type:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Go to the <strong>Toolset <\/strong>\u2192 <strong>Custom Fields<\/strong> page and click on\u00a0 <strong>Add New<\/strong> custom fields group.<\/li><li>Select to create a post field group.<\/li><li>Name your main field group and save it.<\/li><li>To be able to insert a repeatable group of fields, your main group needs to be assigned to a single <a href=\"https:\/\/toolset.com\/glossary\/custom-post-type\/\">post type<\/a>. Click on the <strong>Edit<\/strong> button in the <strong>Where to include this Field Group<\/strong> section and select one post type.<\/li><li>Click on the <strong>Add New Repeatable Group<\/strong> button and give a name to the repeatable group.<\/li><li>You can now use the <strong>Add New Field<\/strong> button inside the repeatable group to add fields to it.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"2f477337c4070b3f18ccfe16949f272d\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/12\/creating-repeatable-field-groups.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/12\/creating-repeatable-field-groups-500x590.png\" alt=\"Repeatable Field Group\" class=\"wp-image-1403143\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Repeatable Field Group<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Editing Content that has Repeatable Field Groups<\/h2>\n\n\n\n<p>When you edit the related posts (in our example, gyms), you can add as many instances of repeatable fields as you need. You can also reorder and delete them.<\/p>\n\n\n\n<p>Click on the <strong>Add new&#8230;<\/strong> button at the bottom right to add another set of fields.<\/p>\n\n\n\n<p>Notice the button at the top-right of the repeating field group editor. This button allows you to switch between horizontal and vertical display for the fields. The horizontal display works like a table. It will show the different fields one next to the other. This layout is convenient for groups that have a few fields. The vertical display works like a list. It&#8217;s convenient for large groups of fields or fields that contain long texts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"displaying-repeatable-field-groups\">Displaying Repeatable Field Groups<\/h2>\n\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"3e1d2592ce20bdf2bf813c9dfa44c991\"><p><span>To display a repeatable field group, you need to use a <a href=\"https:\/\/toolset.com\/fr\/course-lesson\/creating-a-view\/\">View<\/a><\/span><span>. The View will go through all the items in the repeating field group. You can set how it displays each item and the View will produce the required list.<\/span><\/p><\/div>\n\n\n\n<p>To create a View, you need to be familiar with the WordPress Block Editor.<\/p>\n\n\n\n<p>Repeatable field groups are related to a specific post type. In our example, we added them to gyms. This means that you need to edit a <a href=\"https:\/\/toolset.com\/fr\/glossary\/template\/\">template<\/a> for displaying single posts of that post type and add a View that lists the repeatable fields of that particular type (i.e. gyms).<\/p>\n\n\n\n<p>Use the following steps to display repeatable field groups.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Edit the Content Template for single posts of the related post type.<\/li><li>Insert a <strong>View <\/strong>block, give it a name, and select the design options.<\/li><li>In the third step of the View creation wizard, you select the content that this View will display. Select your repeatable field group, under the <strong>Repeatable field groups <\/strong>sub-section. <\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"5c47072feaf9fa00bc2cde97a3250d82\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/09\/repeatable-field-group-view-creation-wizard-1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/09\/repeatable-field-group-view-creation-wizard-1-500x264.png\" alt=\"\" class=\"wp-image-1795547\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Selecting the repeatable field group in the View creation wizard<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Finally, add Toolset blocks to display fields coming from your repeatable field group.<\/li><\/ol>\n\n\n\n<p>In our example, we added two <strong>Single Field <\/strong>blocks. One to display the custom field for the name of the day and another to display a custom field for the opening hours.<\/p>\n\n\n\n<p>And that\u2019s it! Now, when you visit your custom posts on the front-end, you will also see the list of repeatable fields.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"abd2ac875d15ff474068a77f0eb8cefb\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-front-end-500x373.png\" alt=\"Gym opening hours displayed on the front-end using a repeatable field group\" class=\"wp-image-1381265\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Gym opening hours displayed on the front-end using a repeatable field group<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"displaying-repeatable-field-groups-in-custom-order\">Displaying Repeatable Field Groups in Custom Order<\/h3>\n\n\n\n<p>You can easily arrange the order of items in a repeatable field group by drag-and-dropping them. However, by default, the front-end output will not be in this order.<\/p>\n\n\n\n<p>To list items in a custom order, select the main <strong>View <\/strong>block and in the right sidebar, expand the <strong>Ordering Settings <\/strong>section. In the <strong>Sort By <\/strong>dropdown, select the <strong>Field \u2013 toolset-post-sortorder <\/strong>option. Also, select the order to be <strong>Ascending.<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"2ce1fb3dda1bbc2708b8c85662938214\"><img decoding=\"async\" width=\"280\" height=\"638\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-custom-order.png\" alt=\"Displaying the list of repeatable field groups in the custom order\" class=\"wp-image-1381275\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-custom-order.png 280w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-custom-order-66x150.png 66w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-custom-order-132x300.png 132w, https:\/\/toolset.com\/wp-content\/uploads\/2019\/11\/repeatable-field-group-custom-order-228x520.png 228w\" sizes=\"auto, (max-width: 280px) 100vw, 280px\" \/><div class=\"tb-image-caption\"><figcaption>Displaying the list of repeatable field groups in the custom order<\/figcaption><\/div><\/figure>\n<\/div>","protected":false},"author":4341,"featured_media":1625901,"template":"","related-lesson":[8427],"class_list":["post-1624449","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-post-templates"],"_links":{"self":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson\/1624449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/users\/4341"}],"version-history":[{"count":8,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson\/1624449\/revisions"}],"predecessor-version":[{"id":1870223,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson\/1624449\/revisions\/1870223"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/media\/1625901"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/media?parent=1624449"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/related-lesson?post=1624449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}