Skip Navigation

[Resolved] Displaying more than one RFG in a single view for a single post type

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.

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: Africa/Casablanca (GMT+00:00)

This topic contains 4 replies, has 3 voices.

Last updated by Jamal 2 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#2174703

Tell us what you are trying to do?

TLDR: How do you display nested repeated field groups in a single template? I've read all I can find and the snippets of information (some old, some new...but never a complete solution or one that seems to work).

I want to display two sets of RFGs from a single post field group on a single CPT, on a per post basis. Seems easy enough, but the structure of nested RFGs and what has to be done to make them work is challenging for me. "Parent" and "Child" makes sense in many cases, but across all the support and tutorials I have read, these terms fall flat and I struggle to relate them to my exact scenario. Your help would be greatly appreciated.

I have a CPT named Newsletter.
I have a Post Field Group named Newsletter Fields.
Newsletter fields contains: 3 single fields, an RFG, containing fields and another RFG. Structurally, this is my list of fields in the Newsletter Field Group:
1. volume
2. number
3. date
4. [RFG1] = "H2 articles"
a. H2 sort order (number)
b. H2 Title
c. H2 Body
d. [RFG2] = "H3 articles"
i. H3 sort order (number)
ii. H3 Title
iii.H3 Body

I set the Post Field Groups this way to give content authors an easier time writing the newsletter. There will ALWAYS be a list of articles at the H2 level. Some articles at the H2 level may (or may not) have sub-article(s) (H3 level, [RFG2]). I have structured it this way because I'm displaying a table of contents using "LuckyWP Table of Contents" Plugin for ease (I'm not much of a coder).

My expectation, and it seems possible but I have spent HOURS trying...Is to see something like this after I view a single Newsletter CPT:

<h2>1. Welcome to our Club (title)</h2>
<p>H2 body text...Lorem Ipsum...</p>
<h2>2. New Members</h2>
<p>H2 body text...Lorem Ipsum...</p>
<h3> a. John Smith</h3>
<p>H3 body text...Lorem Ipsum...</p>
<h3> b. Susan Jones</h3>
<p>H3 body text...Lorem Ipsum...</p>
<h3>c. Ben Johnson</h3>
<p>H3 body text...Lorem Ipsum...</p>
<h3>d. Alice White</h3>
<p>H3 body text...Lorem Ipsum...</p>
<h2>3. Party - Save the Date</h2>
<p>H2 body text...Lorem Ipsum...</p>
<h2>4. Did you Know?</h2>
<p>H2 body text...Lorem Ipsum...</p>
<h2>5. Events at Upcoming Meeting</h2>
<p>H2 body text...Lorem Ipsum...</p>
<h3>a. Ice Cream Social</h3>
<p>H3 body text...Lorem Ipsum...</p>
<h3>b. Massive Layoff Announcement</h3>
<p>H3 body text...Lorem Ipsum...</p>
<h2>6. Contacts </h2>
<p>H2 body text...Lorem Ipsum...</p>

So, based on my structure above, newsletter authors will create a single newsletter with repeating fields for "title" and "body." The Table on Contents does exactly what I need it to do.

I cannot figure out how to display [RFG2]. No matter what I do I only get [RFG2] (the parent)?. There is a lot of content peripherally related (a couple helpful posts suggested using legacy Views, using shortcodes in the classic editor, making a Relationship filter for the parent on one thing and the a filter for the children something else...but then I keep getting to this stuck point. I have read things like "then just add your shortcode to the parent view." How? Where?

I'm not complaining, I absolutely love your plugin, but the learning curve is steep. I think part of what is difficult is to be expected - your company has grown and matured the products. Classic vs. Blocks and their interplay. Shortcodes, or not. This project is a CPT with Custom Post Fields, with a parent and child RFG, with a view (or two?), a content template. I just need help, with examples, of how to connect to dots. I don't believe I'm asking for anything custom, I think I just need help doing what your awesome product (and this chemists not coder) can do.

Is there any documentation that you are following?
Yes. I have followed nearly every search result for the various search queries. Most of these come from your own support forums or tutorials. But In some ways, my needs are simpler (I don't believe I have to worry about relationships, outside of making sure queries are run on the same post (CPT) for both parent and child custom fields..

Is there a similar example that we can see?

No, I don't have it public yet, but I can get you an account to take a look at what I've been trying. As long as you don't judge me on the number of plugins (it's a risk, there can be issues, etc. etc. I know.). Yes, I have already disabled all plugins but toolset and reverted to twenty nineteen (staging site), but I still couldn't get it to work (because I am making a mistake I just know it).

What is the link to your site?

hidden link

#2175473

Hello, sounds like you have some RFGs set up in a nested structure and you need advice on how to display the content of those RFGs in the template of their containing post type? I can take a look and give you some more direct guidance if you provide a login in the private reply fields here.

#2177821
ct.png
wizard.png

8) Content Templates...I think this is where I'm most confused (e.g. what's the difference between Used on "SEACommnications (single)" vs. "This Content Template is used as the loop block for the View..." I suspect this, or the query filter, is where I've gone wrong.
Okay the difference you're describing is one of assignment. Content Templates can be used in many different ways. One use of a Content Template is where you apply one Content Template (CT) to be used on all posts in a post type. That's what "Used on SEACommunications (single)" means, in general. When any SEACommunications post is loaded on the front-end of the site, this CT will be applied to the post and displayed in the main post content area. Dynamic sources in the template can be configured to display information from the current post, so if you have a Single Field block with a custom field coming from a dynamic source in the current post, the value of the current post's custom field will be displayed there on the front-end.
"This Content Template is used as the loop block for the View..." indicates a different type of assignment for a Content Template. This template is used to design the contents of the loop of a specific View. See the screenshots ct.png and wizard.png attached here. When you use the Loop Wizard during development of a View, by default, a Content Template will be created to hold the contents of one iteration of the loop. Everything you place in the loop template will be repeated for each result in the View. In the code area, you can see the loop template is placed inside the wpv-loop tags using a wpv-post-body shortcode. This is most helpful for complex loop types or loops that contain a large amount of information, and also is required if you want to design the contents of the loop using the Block Editor.
If you disable the CT option in the Loop Wizard, the contents of the loop will be placed directly in the loop output panel where you now see the wpv-post-body shortcode, and no loop template editor would be shown below the loop editor area.

Now that we've discussed loop templates and how they work, let's look at the one you have set up here:
hidden link
This is the loop template for the View of outer RFGs - Article (parent)s. I can see that you have placed a couple of shortcodes here that you want to use to display the inner RFG fields. The problem here is that you need a View to display the contents of the inner RFGs here. It's the same reason you use a View to loop over the outer RFG in the template for SEACommunications. There can be multiple Article (parents) associated with each SEACommunication post. In the same way, there can be multiple Article (child) associated with each Article (parent). So you can't just drop a single shortcode here, you must create a View of the Article (child) RFGs and place that View here in the loop template. Then put your shortcodes in the loop of THAT View to display the fields of each Article (child).

I did a quick scan of the Views you've created already and it looks like the Ralph Children View is the closest to what you'll need here, so I placed it in the loop template where you currently have the article-title-child and article-body-child shortcodes. You can probably delete those. Now I can see the nested RFGs appear in the SEACommunication post on the front-end of the site. Not all the Article (parents) have Article (children), so obviously there aren't children displayed for all parents. In those cases you currently see "No items found" because that's how the Ralph Children View is set up to display when there are no items found:
hidden link
You may want to adjust that. I'm a little confused by what I'm seeing now, so I think it's time for you to jump in and take another look. Considering the nested RFG content, I see there are two wpv-post-body shortcodes in the loop of the Ralph Children View, so I would start my investigation there to understand what is going on. You may need to revise the contents of those templates, or delete one or the other of them, because I see the SEACommunications and Table of contents headers repeating over and over and that looks odd.

Let me know what you need next.

#2178099

Hi Chrstian,

YOU ARE AMAZING. Thank you so much for the thorough explanation. It certainly has helped me better understand the terminology of this. Toolset is truly amazing (the products and the support).

I figured out (sort of by trial-and-error) how to remove the repeated header. Strangely, what I had to do was go to the child view loop, and in the Wizard, un-tick the box to "Use CPT to group...". Then, upon saving and refresh, poof, the "extra header" content was gone. I don't really understand that. I can't figure out what the underlying query was that was pulling them into the child loop view, but...doesn't matter, it's fixed.

You really helped me a lot, if you take a look now, it's looking MUCH better, thanks to you (hidden link) [login, it's not posted externally anywhere yet].

I think we can close the ticket for now. You've been an amazing help.

Tim

#2179645

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello there! Christian is not available today. I'll set this ticket as resolved.

Let us know if you need any further assistance.

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