Skip Navigation

[Resolved] Split: Displaying repeating fields

This support ticket is created 2 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 10 replies, has 2 voices.

Last updated by Waqar 2 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#2222201

Hello Waqar,

I'm having trouble displaying repeating fields. I've set them up apparently fine, and filled them when available, but I'm unable to add them to the content template? No fields appear when I select the custom field group for the cd (see second attached image.) I'm probably missing something very basic... but what?

Thanks again and best regards,

Ludovic

#2222313

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

If the target field is a part of a repeating field group, you'll need to use a view, to show them, as explained in this guide:
https://toolset.com/course-lesson/creating-and-displaying-repeatable-field-groups/#displaying-repeatable-field-groups

If it is a regular repeating field and it is not showing as an option in the repeating field block's settings, I'll use the admin access details from the other ticket, to see how this template and the field are set up.

regards,
Waqar

#2222827
Screenshot Repeating in single post.png
Screenshot Repeating in post loop.png

Hello,

Using the linked page, I was able to create the loop for the repeatuing fields (I must have missed that in the video!) and...

...I was happy it worked *in the content template*.

When displayed on the page (i.e., the repeatable field loop inside the posts loop) I get my custom "no content found" message. But when displayed in a single post, I get the items I'm expecting.

So I MUST have missed something... but what?

See attached images, and have a look with the credentials submitted separately.

Thanks!

#2224031

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

To create a common view that can work on the single post page as well as from inside another view's list, you'll need to use a classic/legacy view:

1. Please go to WP Admin -> Toolset Views and you'll see a new view named "View to show related Récompenses".

This view is set to show the "Récompenses" posts (repeating field groups), with query filter set to "related to the Post with ID set by the shortcode attribute wpvrelatedto".

This will give you the ability to pass the target "CDs" post's ID, in the shortcode attribute.

2. Next, in your content template "Modèle pour CDs", you can insert the shortcode for this new view, like this:


[wpv-view name="view-to-show-related-recompenses" wpvrelatedto="[wpv-post-id]"]

As we have passed the current CDs post ID using the "wpv-post-id" shortcode in the view's shortcode, it works on the single post page as well as from inside another view's loop, for example, the "Discographie" page.

Note: You can remove the blocks based "Récompenses" view from the template "Modèle pour CDs".

#2224343

Ah, I see. I'm not sure I wholly understand what you did there, but the magic worked.

I worry only because I watched to videos about repeatable fields, and either I missed it or none mention this way of dong things... I still don't get why one would work in single post and not in loops, while your solution does, but that's not that important.

What IS important though is that, in "my" way, I was able to style the image list as I wanted, by setting an image size and having them on a row. Now they do appear in the loop, but I wasn't able to find out how to make them smaller (the set size I had before) and especially in a row... in a column it takes far too much space and creates a focus that shouldn't be there.

I saw the example about gym opening hours, which are, and with good reason, listed in a column of items. But I think there was also another example about... gym types, maybe? where they were queued in a single line.

I have no doubt this can be done, I'm just (as usual) missing something. If you can point me to some resource that could help me do it, that'd be great (I feel bad about having you do all my work ^-^)

Best,

Ludovic

#2224895

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

For this specific requirement, we had to use the classic/legacy views editor, because, in the Blocks based view, it is not possible to set the target post for the relationship filter, using the shortcode attribute.

The documentation on using the classic/legacy views editor is available at:
https://toolset.com/documentation/legacy-features/views-plugin/

To make the images show in a smaller size and in a grid/columns, you can include the following CSS code in the view's "CSS editor":
( screenshot: hidden link )


div[class*="layout-1051-"] .wp-block-image {
    display: inline-block;
    vertical-align: middle;
    text-align: center;
    padding: 1em;
    width: 15%;
    max-width: 15%;
    margin: 0;
}

#2229357

Hello Anwar,

Again thanks for the detailed and fast reply.

I'm just worried that I went to a uselessly complicated way of doing things. It does work fine, and I could leave at that, but it seems there is / should be a better way? MAybe I am really missing something here, but why can't I make it work like the Recipes examples (https://toolset.com/lesson-placement/lesson-placements-1647613-1621091/)?

There the ingredients are also a repeating field, and it's displayed without creating views and adding CSS?

I really want to understand this, because I feel I'm missing some basic elements I haven't udnerstood and went on a way that makes things more complicated than they should. Or, if - with my needs as they stand - it's the only way, let me know as well (but I'd be surprised since it's anything but simple, straightforward, and visual like Toolset is for everything - thankfully :-))

Best,

Ludovic

#2229551

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I'll be happy to clarify the difference.

1. Regular Approach:

In a regular approach, one would design a view using the blocks editor, to show the related repeatable field group items, inside the single post page and it works as expected.
( just as the "Récompenses" view worked for you, in the single "CDs" post template, and is covered in the guides/tutorial that you referenced )

2. Approach to fulfill your requirement:

But, in your particular requirement, there was an added challenge. You wanted to re-use the view "Récompenses", inside the loop of another view's loop, which is not supported.

This is why I guided you towards using a classic/legacy view where this can be achieved by passing the target parent "CDs" post's ID in the shortcode attribute. But using the classic/legacy view comes with a limitation of fewer styling options, compared to the blocks editor view and this is why some custom CSS code was needed.

I hope this explanation clarifies, why we had to follow additional steps to show the repeatable field groups items.

If you'd prefer to use the blocks-based view "Récompenses" in the "Modèle pour CDs" template, you can do that and remove the shortcode for the classic/legacy view "View to show related Récompenses".

And whenever, you need to show the related repeatable field groups items, inside the loop of another view, that is showing the "CDs" posts, you can use the classic/legacy view "View to show related Récompenses".

#2231505

>1. Regular Approach:
>In a regular approach, one would design a view using the blocks editor,
> to show the related repeatable field group items, inside the single post page
> and it works as expected.

But that's exactly what puzzles me: in the gyms example, the list of opening hours is *also* a repeatable field, and it *is* displayed very simply inside the archive/all posts page (on top of the single post page) without any need to "re-use" anything.

> But, in your particular requirement, there was an added challenge.
> You wanted to re-use the view "Récompenses", inside the loop of another view's loop,
> which is not supported.

I feel like I went wrong from the outset, and instead of creating the CPT like it's done for the gyms, I made a mistake which forced the workaround. Because otherwise I just can't understand why the video for the gyms examples breezes through displaying the repeatable field for opening hours and I couldn't.

Should I give it another try to see if I can get it to work as in the video? Any idea where I went wrong?

(And sure, it now works fine - thanks for that - but for my own peace of mind, I would like to understand what I did wrong that made it ipossible to obtain the result like in gyms and then forced you to come up with a "cheat" to make it work anyway.)

Best,

Ludovic

#2231793

Oh - CR*P!

I wanted to delete the non-working repeatable field for Récompenses that I had created... and of COURSE I ended up deleteing the one you had added.

In the CD content template, the "Fields and text" still exists, but the custom field is missing from the Field group for CDs.

I can't for the life of me recreate it - what I tried doesn't seem to work, as the repeatable field didn't appear in the view anymore, and re-adding one to the field group allowed me to check it in the view, but to no effect. I tried various settings for the "post relationship or repeatable fields group owner " without any more success.

I tried to understand the steps above but obviously failed, the loop you had created says there is content linked to it.

I feel FAR more stupid than I have in a LONG time. I'm an idiot. Please help - and forgive me.

Ludovic

#2232165

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

> But that's exactly what puzzles me: in the gyms example, the list of opening hours is
> *also* a repeatable field, and it *is* displayed very simply inside the archive/all posts
> page (on top of the single post page) without any need to "re-use" anything.

- I've searched through the "Gyms and Trainers" demo website, but couldn't find any archive or page, that is listing multiple "Gyms" posts, and also lists their related "Opening Hours" from the repeatable field groups.
hidden link

The related "Opening Hours" entries are showing for each "Gym" on the single Gym post pages, for example:
hidden link
hidden link
hidden link

If you can share a link to any archive or page, where multiple Gyms are showing along with their opening hours (all on the same page), please share it with me.

I noticed that in the field group "Groupe de champs pour Disques", the repeatable field group named "Récompenses obtenue" was added with an image type field "Logo récompense".

To make this new field, work from the view "View to show related Récompenses", I made the following changes:

1. In the query filter settings of the view, I selected the option "The post with ID set by the shortcode attribute: wpvrelatedto"
( screenshot: hidden link )

This is because, we want the view to use the 'CD' post whose ID is passed in the shortcode of the view, as a reference.

2. Next, I opened the content template for this view ( screenshot: hidden link ) and then selected the new "Logo récompense" field, in the Image block's settings ( screenshot: hidden link ).

As a result, the image logo from the "Logo récompense" field is showing for the CD post "L’Alchimiste – les Années de jeunesse" on its single page, as well as on the "Discographie".

hidden link
hidden link

When you'll add the repeating field entries for the other CD posts too, they'll start showing as well.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.