Skip Navigation

[Resolved] To display repeating field still need wpv-for-each?

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to use wpv-for-each to iterate over repeating fields of a parent post?

Adding the id="$parent-slug" attribute to wpv-for-each doesn't work.

Solution:
It is not possible to set the parent directly on the wpv-for-each shortcode.

You can make this work by creating an unassigned Content Template which uses wpv-for-each and which doesn't include any id attributes, so that the shortcodes use the "current" post for their context.

But you then insert that Content Template into your template for the child posts and this is where you add the id attribute, so that for that nested Content Template its context is the parent post.

This support ticket is created 6 years, 11 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Jeffrey 6 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#609204

Today I am trying to display repeating parent image type field with a lightbox plugin, it seems which [wpv-for-each][/wpv-for-each] is unnecessary. if I add the shortcode, the images are not shown up in fron-end, as long as I got ride of the shortcode, the images were shown. So I just wonder if this shortcode will not be necessary now? but another question appeared, can I display repeating parent image type field with lightbox plugin? because it is not working now. Thank you

#609304

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Jeffrey

When you say "parent image type field" do you mean an image custom field belonging to a parent post?

So you would output the image using the types shortcode using the id="$parent-slug" attribute?

If that custom field is a repeating field then it would normally output all instances of the field, unless you use the index attribute to specify which one to output (see https://toolset.com/documentation/customizing-sites-using-php/functions/#image and the More section).

If you want to use the image fields with a lightbox plugin then you will have to ensure that the markup generated is in the format required.

See this document for a description of how to add a slider using repeating image fields to get an idea of what's involved: hidden link

#619261

Hi Nigel, it was done, but in each lightbox plugin, parent field cannot be displayed in lightbox, that means I can not use $id=‘parent-field’ into repeating field shortcode. maybe it is a small bug.

#619700

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Jeffrey

I tried this on my test site and, you are right, it doesn't work.

Looking at the documentation for the wpv-for-each shortcode it seems that id is not available as an attribute: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

So it is not possible to set the parent directly on the wpv-for-each shortcode.

I haven't tested it but I think you could get it to work by creating an unassigned Content Template which has the markup for the slider and which doesn't include any id attributes, so that the shortcodes use the "current" post for their context.

But you then insert that Content Template into your template for the child posts and this is where you add the id attribute, so that for that nested Content Template its context is the parent post.

#619882

Thank you so much for the help, I will try 🙂