Skip Navigation

[Resolved] Show the “Parent Posts” of Repeatable field Groups (RFG)

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

Problem:
Can we create a list of Posts, which have RFG (Repeatable Field Groups) assigned to them?
Or, can we create lists of Parent posts to some RFG?

Solution:
Yes, however it's not possible with the GUI only, you'd need to follow the logic described here, to achieve it:
https://toolset.com/forums/topic/create-a-view-that-lists-all-posts-with-repeatable-field-groups/#post-1191399

This support ticket is created 5 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by Matthias 5 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#1191157

Hello Toolset Support,

I'm using repeatable field groups in my posts for displaying products with some custom fields (title, link, image). I created a view to display the groups in my posts and this works great so far.

But I need help with something:
As we will have a lot of posts that will contain repeatable field groups, we need some kind of overview for internal use and I'd like to create a view which lists all published posts where field groups are used. The list should display the linked post title, the post date and all entries from the field groups. Is this possible?

Thanks in advance for your help!

Best regards
Matthias

#1191399

You would just call back the parent posts of the currently displayed RFG (Repeatable Field Group), in the View loop.

This would then automatically exclude posts that have no RFG, since the View will never display an RFG that doesn't exist, and since you callback it's a parent (the owner post), you see only the posts data with RFG attached.

It's easier to do than it reads, I hope ?

1. Create a View, and query the RFG (all of them, set no parent post, so you get all RFG items available of that RFG type)
==> Ignore the annoying "Do not forget to add a filter by post relationship or repeatable fields group owner and select the right owner for the groups that you want to display." - It's not required.
2. In the Loop call back the parent of the RFG:

[wpv-post-title item="@SLUG-OF-RFG.parent"]

(adjust SLUG-OF-RFG)
3. Insert this View to a page

Right, now you see, for each RFG that exists, the parent post title (the post it belongs).
And that's correct, you see repeated entries because there are many RFG belonging to one post, and we loop over all of them and output the Post each time!

To correct that, the last strike below is used 😉

4. Add a Query filter to your View that says:

Select items with field:
toolset-post-sortorder is a number equal to 1

That this does, is make sure only the first RFG of each post is rendering it's parent post data in the loop.

So now your view, seen on the page, should show a list of unique post titles which have at least one RFG.

This kind of View might get a little expensive if you have many posts and relations, that could then be corrected with some pagination or caching mechanisms

#1192130

This works! Sometimes it's so easy. 🙂

But the filter only works, if you have more than one RFG item. For a single item the meta key doesn't exist. But that's ok for me because I need to list all items and parent posts anyway. I will manage long lists with pagination or date filters.