Skip Navigation

[Resolved] sort custom post by date stored inside Repeatable Field Groups

This support ticket is created 5 years, 10 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: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by pharmaklaus 5 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1203870
view1.png
view2.png
person1.png
person2.png
people_cf.png

Hi,
I have a custom post type for people (Tom, John, Mario, etc.).
Every person has a Repeatable Field Groups [group slug: carica-info] to define the institutional position (carica) with the start and end date.

Inside the repeatable field groups, there are two custom fields that I want to use to filter and sort the main query (Tom, John, etc.): a select [carica-organo] and a start date [carica-data-inizio].

I want to do something like this:
1) Select custom posts that have at least one repeating field with [carica-organo="director"], someone has more than one repeating field set as "director" with different start-end date.
2) Sort all the custom posts by start date.

I have also a taxonomy associated with the custom post-type and the value are the same as [carica-organo].
I'm using two views, the first one to filter the post type by category so I select every person with category=director
In the second view, I can only sort the institutional position (carica) for the current person.

Thanks in advance
Cheers

#1204436

Hi there,

Thank you for contacting us and I'll be happy to assist.

The way repeating field group's data is stored in relation to its parent post, it won't be possible to add a filter to the main post type's query, based on the custom field value that is part of the repeating field group.

A neater and more efficient way to achieve this would be to replace the repeating field group with a post-relationship.
( ref: https://toolset.com/documentation/post-relationships/ )

You can remove the repeating field group "carica-info" and instead register a new custom post type with the same name "Carica Info". Any custom fields which were part of the repeating field group can be added into this new custom post type.

Next, you can create a "One-to-Many" relationship between the main "Rappresentanti" post type and the new "Carica Info" post type, so that each "Rappresentanti" post can be linked to multiple "Carica Info" posts.

After that, you'll be able to create a view that can show results ( Carica Info ), sorted on the basis of the starting date value. And inside the view, you can show the information about the connected "Rappresentanti" post.
( ref: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/ )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1236461

My issue is resolved now. Thank you!