Skip Navigation

[Resolved] Date Only Filter is filtering also by time.

This thread is resolved. Here is a description of the problem and solution.

Problem:

Setup query filter on custom date field in post view.

Solution:

You can follow our document to setup the date filter:

https://toolset.com/documentation/user-guides/views/date-filters/

Relevant Documentation:

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

Last updated by andrewD-10 2 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2312429

Tell us what you are trying to do?

I have a table view that shows all my posts. I have and "Entry Date" custom field that we use to filter projects by the date they were entered.

I have a post (Post A) that has a toolset entry date of 03/08/2022 and when I search on my table for entry Date 03/08/2022 it shows up just fine. Post A was published on 03/08/2022 at 7:39 AM (WordPress's Posted Date and Time).

However, another post (Post B) has a toolset entry date of 03/08/2022 as well, but it does not show on my table. Post B was published on 03/08/2022 at 11:12 AM (WordPress's Posted Date and Time).

The current PST time is 8:50 AM.

My conclusion is that the entry date is not only filtering by the date 03/08/2022 but also by the current time I have set up in my wordpress settings PST.

Is there a way to correct this, in that, when I search for an toolset date only field (no time picker) that the search results would include everything from 03/08/2022 12:00AM to 03/08/2022 11:59 PM?

#2312853

Hello,

Toolset custom date field stores value in timestamp format, if you filter the result using value 03/08/2022, it will output results with value 03/08/2022 00:00 AM, if you want to display results of 03/08/2022 whole day, you need to filter the results with date range, for example: 03/08/2022 00:00 ~ 03/08/2022 24:00

More help:
https://toolset.com/documentation/user-guides/views/date-filters/
section "Filtering Between Dates"

#2313487

Hi Luo,

It is a Date only custom field. So I do not have a time involved and it should just show the date that I entered.

This used to work just fine, but as I look today it seems to not work.

I may need custom code to fix this as I need it to be very easy for my customers to select a date and each post with the date should show up. Can you help me with this?

#2313493

Also, even if the code will show only 03/08/2022 00:00. I post nothing at midnight. So therefore no post should ever show up as there will be zero posts with an exact date of 03/08/2022.

But lets just say toolset is designed to put a date and time of 03/08/2022 00:00. Why isn't every project showing up??? It seems that toolset is actually doing 03/08/2022 with a time equal to the current time of entering the project. Ex: It is 9:00 AM, when I select the date toolset seems to be doing this.. 03/08/2022 09:00. Which as you mentioned should not be happening as it should be putting 03/08/2022 00:00 regardless if it is 9:00 AM or 2:00 PM. Because a date only custom field is designed to put a time of 00:00.

Do you see where this is a problem?

#2313501

Hi Luo,

Also, something I noticed.

Today is 03/10/2022. When I search for an entry date of 03/09/2022 only 19 results show up as it is 8:31 PST.

But when I search for an entry date of 03/08/2022, I see all 50 results equalling all posts I entered that day of 03/08.

Why is this only happening on yesterday's date?

#2313511
Screen Shot 2022-03-10 at 10.35.07 AM.png

Sorry about the multiple messages, I just wanted to lastly show you that I even tried with a between date, but it is still filtering out all the times that has not come yet. Ex each post that was posted before the current time of 8:31 AM is showing, but each post that was posted after is not showing.

Even though I am technically searching for posts 03/09/2022 00:00 through 03/10/2022 00:00. Please see screenshot.

There is another issue going on and it only happens on yesterday's date.

PS: total results show are 19. I entered a roughly 50 posts on 03/09. So the results should be around 50

#2313535

Hi Luo,

I found my issue. I have a custom code active that will show only yesterday's projects as I did not want my customers to see the posts we enter right away. I wanted there to be a 1 day gap between what the customers see and what we currently are publishing so that way my QC can check each post and make sure it is ready for customers to see.

With this being said, I will open a new support case and see if we can fix the code to show all projects from today at 00:00 and backwards (ie: do not show projects that were published todays date at 00:00 midnight and forward).

The code is here:

<?php
/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

function tssupp_before_n_days_ago($view_args, $view_settings, $view_id)
{
$view_ids = array( 40875, 40343, ); // Apply the older than yesterday filter to these View IDs

if ( in_array($view_id, $view_ids) ) {

$view_args['date_query'] = array(
'before' => '1 day ago',
'column' => 'post_date'
);
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_before_n_days_ago', 99, 3);