Skip Navigation

[Resolved] view filter based on date range of post created date

This support ticket is created 4 years, 9 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by rohanA 4 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1534041

Tell us what you are trying to do?
I am trying to filter a view based on date range of post created date (e.g. 05-01-2020 to 28-02-2020)

Is there a similar example that we can see?
Following the reference of - https://toolset.com/forums/topic/filter-post-by-date-range/#post-1528551

I have created front end fields:
from: [wpv-control-postmeta field="date-from" type="textfield" placeholder="dd-mm-yyyy" url_param="date-from"]<br />
to: [wpv-control-postmeta field="date-to" type="textfield" placeholder="dd-mm-yyyy" url_param="date-to"]<br />

and using the following in my themes functions.php file
//------- filter post by date range -----
add_filter('wpv_filter_query', function($args, $settings, $view_id){
if($view_id == 387){
if(isset($_GET['date-from'])){
$args['date_query']['after'] = $_GET['date-from'];
}
if(isset($_GET['date-to'])){
$args['date_query']['before'] = $_GET['date-to'];
}
}
return $args;
}, 999, 3);
//------- end filter post by date range -----

The date range is being passed to the url but on clicking submit, I get a 'No items found' result. Any help would be greatly appreciated.

#1535109

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - you want to display the view which offer you the filter to filter the custom field date which actually holds value of start date and end-date - correct? The date-from and date-to is setup as custom fileds or you want to filter the post for default published date?

Can you please share the problem URL where you added the view as well as access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1535151
Screen Shot 2020-03-02 at 8.33.13 pm.png

I'm working on my localhost.

I want to filter the posts for default published date between certain values (e.g. 05-01-2020 to 28-02-2020).

#1535181

Minesh
Supporter

Languages: English (English )

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

Ok - can you please send me full screenshot of your edit view page and please make sure the Query Filter section should be visible on your edit view page.

#1535399
combined.jpg

I have attached the screenshot.

I also created a custom date field, and tried to filter between values for the date field, but that didn't work as well.

#1537059

My issue is resolved now. Thank you!