Skip Navigation

[Resolved] Filter by Date

This support ticket is created 6 years, 1 month 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 8 replies, has 4 voices.

Last updated by Luo Yang 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#1122808
date.PNG

Hi - I'm just inquiring if there has been any update on a feature that was requested a while ago. The ability to use Parametric search to filter a view of posts by Date created.

I.e - A drop down filter that can filter posts by month created.

Thanks!

#1123543

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - there is no filter/feature available yet to filter your view by default post date as of now.

As you can see the feature request is already accepted and we have an internal ticket for it where I added your voice.
=> https://toolset.com/feature-request/add-front-end-parametric-search-elements-filter-for-post-date/

This feature is set to release with View's version 2.8 in future. Please note that there is no ETA on it.

As a workaround - you can always use view's filter wpv_filter_query that will help you to modify your view's query on fly.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

The following ticket may help you or show you a way how you can use "wpv_filter_query" hook:
=> https://toolset.com/forums/topic/problems-with-filtering-views-query-by-date/#post-577336

#1127368

Hi Minesh - I'm not sure I understand. Maybe I'm using the wrong terminology. I think what you are explaining here is how to filter a view down to a certain time period. I.e embed a view in a page that only shows posts from a certain time period.

What I am trying to do is use a parametric search to allow my users to filter a view by post date.

So... I have posts going back several years. I will display all these posts in a view. I want the user to be able to filter down the list on the front end and show posts from any date - they might want to see all posts from September 2017 or January 2018 etc etc (see screenshot date.png for what I would want the user to see on the front end)

A bit like what you helped me with in this ticket (but for date not post status)

https://toolset.com/forums/topic/parametric-search-to-filter-a-view-by-post-status/

Is that possible? Thanks

#1127491

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Minesh is sick and I'm looking over his support threads.

I think Minesh understood you correctly.

We have a request for the feature you mentioned.

To achieve something similar you would need to modify the query that retrieves posts to manually set up a post_date filter using the API hook wpv_filter_query.

The problem with adding this as a custom search filter is that you need to add the form control to your View to show the dropdown that from which users will select a date. You would need to manually add the markup for such a control, and include a submit button to trigger the search. You would be able to retrieve the submitted date from the $_REQUEST object to use to build the date query arguments in your wpv_filter_query hook.

#1127571

Hi Nigel,

Really sorry - I don't really understand what you are suggesting I do. My development skills are fairly basic! Is there any chance you could provide an example that I can copy and paste??

Thanks!

#1129204

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, it's not so simple, because you need to create a custom form control as well as add server-side handling using our API and the wpv_filter_query hook.

If it were just a question of a few lines of sample code to demonstrate how to use wpv_filter_query I could do that, but for this you'll need to either wait for the feature to be added to Views, or arrange for a developer to do the custom work for you. (See https://toolset.com/contractors/)

#1129696

Hi,

There isn't existed solution for it, as a workaround, you can setup a custom taxonomy , for example "post-month", edit each post setup term value as below:
February 2018
March 2018

Then you will be able to setup the filter in custom search form as your screenshot
hidden link

#1131936

Hi Luo

Thanks for getting back to me!

Can I just check, are you saying create a taxonomy called Post Month and then manually go into each post and tag as the month it was created. And then do that each time a new post is created - or have I misunderstood?

If so, I don't think that will work in this use case. I think I would need it to be automatically populated with the date created because I won't be creating the posts, it will be lots of different users. Just as some background....

I'm trying to create a Q and A functionality for our intranet, where employees can ask questions to our leadership team. I want to display all the answered questions in a view and have them filterable by month answered. I.e a user can use the parametric search for example to show them all the questions that were answered in September 2017.

btw - really appreciate all you guys help so far with this one!

#1132493

For the question:
Can I just check, are you saying create a taxonomy called Post Month and then manually go into each post and tag as the month it was created
It needs custom codes, for example, when user save the post, you can use action hook "save_post" to trigger a PHP function, https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

In this function, get month + year value from post publish date
https://developer.wordpress.org/reference/functions/get_the_date/

then save it into your custom taxonomy "post-month"
https://developer.wordpress.org/reference/functions/wp_set_object_terms/

For your reference.