Skip Navigation

[Resolved] Filtering a View by a Date Field in a Repeating Field Group

This support ticket is created 5 years, 4 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1307451

I have a CPT for Tours and some Tour runs several times per year, so I have a custom field group that has the start and end dates for when they run.

hidden link

So for example this Tour runs 5 times in 2019.
hidden link

Some Tours will have just 2019 dates and some will also have 2020 dates.

I currently have a Tours page that outputs all the Tours:
hidden link

But I want to have a page/View that outputs the Tours that have 2019 dates and another page that outputs the Tours that have 2020 dates. Is there a way I can filter this View by the year from that custom field group?

Thanks,

Tim

#1307595

Hello,

The Toolset Reapitable Field Groups are based on one-to-many relationships, so each item of Reapitable Field Groups is also a single post.

In your case, you can try these:
1) Create two different pages:
- 2019 Tours page
- 2020 Tours page

2) Create two different post view, for example:
a) 2019 post view
- Query posts of "Reapitable Field Groups"
- Filter by:
Select items with field:
start-date is a number between DATE(01, 01, 2019), DATE(01, 01, 2020)
https://toolset.com/documentation/user-guides/date-filters/
- in section "Loop Editor", within Views loop, display it's parent Tour post information, see our document:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

b) 2020 post view, same as above, you just need to change to filter as below:
Select items with field:
start-date is a number between DATE(01, 01, 2020), DATE(01, 01, 2021)

#1307865

Thanks Luo,

I had to manually find the repeating field group slug, it didn't appear in the Post Selection tab, but it seems I got this working:
[wpv-post-featured-image size="full" item="@dates-tour-leaders.parent"]

But this isn't quite what I need because it will output the parent post multiple times if there are more than one Tour Dates that have the Start Date in 2020. I just need to show each Tour that has a Start Date in 2020.

Tim

#1309113

That is expected result, as I mentioned above:
Toolset Reapitable Field Groups are based on one-to-many relationships, each item of Reapitable Field Groups is also a single post.

So one "Tour" posts can connected to multiple "repeating field group" posts, as a result, when you query "repeating field group" posts, and display their parent "Tour" post 's information, it will output parent "Tour" post multiple times.

As a workaround, you can try these:
1) Create a post view "2020-tour-date":
- Query "dates-tour-leaders" post
- Filter by:
Select items with field:
start-date is a number between DATE(01, 01, 2020), DATE(01, 01, 2021)
- in section "Loop Editor", within Views loop <wpv-loop> ... </wpv-loop>, display it's parent tour post IDs only, as below:

[wpv-item index=1][wpv-post-id item="@dates-tour-leaders.parent"][wpv-item index=other], [wpv-post-id item="@dates-tour-leaders.parent"]

- Enable option "Disable the wrapping DIV around the View"

2) Create a post view "2020-tour-posts":
- Query "tour" post
- filter by: Post ID filter
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
- within Views loop, display "tour" post information

3) Create a wordpress page "2020-tours"
Display above post view's shortcode(step 2), with "ids" attribute of post view "2020-tour-date", for example:

[wpv-view name='2020-tour-posts' ids='[wpv-view name="2020-tour-date"]']

More help:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes