Skip Navigation

[Resolved] Need help to filter with dates

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 replies, has 2 voices.

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

Assisted by: Luo Yang.

Author
Posts
#1326653

Boy, I never thought that would be so complicated...

I have publications (with different articles in them... but that's another topic)... They are custom types and the issue number is the title...

In them, I have a custom field called "Date Edition" (in French, ex: 1 novembre 2018).

What I need to do is basically replicate that page: hidden link

So, my guess is that I'm going to need two Views: one to get the year and the second one that will get all the publications of that year...

I started by trying to create a filter that would be between January 1st of a specified year (for testing, I entered a constant, like 2017) and december 31st of the same year (I could use January of next year to make sure, but anyway, they are always labeled as the first of the month)...

I then discovered that for a weird reason, we can't filter by date... We need to use a numberic field... So, if I use constant, it works... but, since that will probably be in a View that will call it and pass to is a year, I tried to use shortcodes... BUT, there might be something I don't understand, as if I choose
Date Edition field with number between shortcode for first line, then I can only enter lowercase letter and numbers... so, I used as the parameter "startdate"... and then a second shortcode called "enddate"...

When I insert this View in a page, it automatically gives me ONE field called wpcf-date-edition and the value that I must put there is a timestamp... But there is no way to calculate that... So, from my research, all I can do is create a function that would convert a year to a timestamp... But I'm not totally comfortable with that and with using PHP... hence why I bought Views (Toolset)... Is there a way to do it visually? If not, I have no idea how to create the function (I can put it in Code Snippets plugin) and how to call/use it in my view...

Can you help me? Is there documentation on that?

#1326657

I have a feeling that I'll need to create everything in PHP, because I can't find a way to use, for example, JavaScript to create a loop (from current year, for example, to 1988 (first year)) that will in turn call my View...

So, I guess I will need a PHP loop that can call a View... not sure how to do that, though...

#1326675

Hello,

I have checked the URL you mentioned above, in this case, I suggest you try these:
1) add a custom taxonomy "year", register it to post type "publications"
2) Edit each post, setup the term in taxonomy "year"
3) Create nested view:
a) Parent taxonomy view:
- Query terms of taxonomy "year"
- Display below child post view
b) Child post view
- Query "publications" posts
- Filter by taxonomy "year" set by parent taxonomy view

See our document:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
Views Inside Views – Display Nested Multidimensional Lists

#1327085

Thank you.

I thought about it... The problems are:
1- The data is already present, in the form of Date Edition... So, creating another taxonomy called year would duplicate that data...
2- There are already more than 300 entries in the publications (I have imported them from another site/database with WP All Import)... So, it would be long to go through all of them to add it... I still need to reimport them/update them, maybe I could add an SQL query that would get the year and put it in that field...

I saw some examples of custom functions where we can create our own SQL query... Is there extensive documentation on how to create an use those functions?

#1327691

There isn't such kind of extensive documentation on how to create an use those functions:
add an SQL query that would get the year and put it in that field...

But it is possible setup the taxonomy values in your CSV file, see our document:
https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/

For example "WP All Import" plugin, it supports importing taxonomy too.
https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/how-to-import-data-from-a-csv-file-using-the-wp-all-import-toolset-types-add-on-plugin/

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