Skip Navigation

[Resolved] Query filter for field value equal to todays date

This support ticket is created 3 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.

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 17 replies, has 2 voices.

Last updated by jamesR-13 3 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1993723

Tell us what you are trying to do?
Query filter for field value equal to todays date

What is the link to your site?
requests.ipsglobal.com

I have custom post type with a custom field value that is populated with today's date when a certain form is submitted.

I need to create a view that shows posts with that field's value matching today's date.

#1993849

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi James,

Thank you for getting in touch. If you want to filter the view by the custom field for posts from Today() you will need to use a combination filter with Between.

So the filter should read "The field XYZ is a number that is Between TODAY and Future Day 1"

For more information on date filters please have a look at the link below.
https://toolset.com/documentation/user-guides/views/date-filters/

Please let me know if this helps.
Thanks,
Shane

#1993871

The filter isn't working.

I specifically want to match to today's date. I have set the field value manually as well as programmatically, and no matter how I configure the query filter, it doesn't display correctly. It either includes posts with non-matching field values, or it shows no matching posts.

I have set a single post specifically with an exact match on the field, and it doesn't show when I filter... probably need to have you log in and look at the site itself. Please enable private replies for me. Thank you.

#1993875

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

I've enabled the private field for your next response.

please also send the url for the page as well.

#1996309

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi James,

Thank you for the patience, I had a look on this again in further details. Your filters are indeed correct.

The issue is that none of your posts meet the criteria set out in the filters. I've created a test post here
hidden link

That is now displaying based on your filter parameters .
hidden link

Thanks,
Shane

#1996333

So, I chabged the status to pending and cleared the approved date, and used my program code to change them back, and now 1956 that you created also doesn't show in the today's approvals view, even though it shows the same numeric timestamp.

How did you set the approved status and date previously?

Perhaps there is something wrong with my php code...

#1996667

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi James,

Something odd is happening here. I created a new post and it worked. Checking on my previous post that I had linked to, it wasn't showing up, however after hitting the update button it began showing up.

Same for some of your other posts, however for your posts what i had to do was to set the date again to Monday 22 , 2021 for those that have today's date.

How are these posts created? Are they created through the backend like how I created my 2 test posts?

Please let me know.

Thanks,
Shane

#1996749

New requisitions are created on the front end through a form at :

hidden link

After they are submitted, they are then approved via form 302, which is hooked to the following code:

	{
		update_post_meta($post_id, 'wpcf-status', 'Approved');
		update_post_meta($post_id, 'wpcf-date-approved', $now);
		update_post_meta($post_id, 'wpcf-approver-email', $current_user_email);
	}

and here is my php code for the $now variable:

	date_default_timezone_set('America/Denver');
	$now = time();
	$now = date("m/d/y",strtotime("now"));
#1996771

no, they are created on the front end at hidden link

then once they have been submitted, form 302 on the front end is used to approve them, which sets the date that I am trying to filter on with some php code. Here is my php code:

	{
		update_post_meta($post_id, 'wpcf-status', 'Approved');
		update_post_meta($post_id, 'wpcf-date-approved', $now);
		update_post_meta($post_id, 'wpcf-approver-email', $current_user_email);
	}

and here is my code the $now variable referenced above:

	date_default_timezone_set('America/Denver');
	$now = time();
	$now = date("m/d/y",strtotime("now"));
#1997801

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi James,

I figured the issue you are having, your posts are being created with a different timestamp than what your shortcode is providing.

For e.g I did a test with the date created field and when the posts are created they are created with 1616479200 however your shortcode is passing the following 1616457600

Both timestamps are from the same day, however they are both different in terms of the time of day.

I believe you should just set the date similarly to how you are doing it in the shortcode for today because when setting date only you want to have the midnight value and not any specific time in the day which is what is happening when you're setting the timezone information on the function as well.

Please do this and let me know if the issue still remains, as mentioned when the posts are created on the backend and the date set in the field, it displays fine but your timezone settings is changing the actual timestamp of the field.

Thanks,
Shane

#1997999

So, I changed my code for the $now variable to just fire the [today] shortcode that I am using as an attribute for the filter query, aaaaand.... still no love. The field is filled, the values appear to match, but the requisitions do not appear in the view.

Please advise...

#1998041

So, I changed my code for the $now variable to just fire the [today] shortcode that I am using as an attribute for the filter query, aaaaand.... still no love. The field is filled, the values appear to match, but the requisitions do not appear in the view.

Please advise...

#1998381

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi James,

I've modified your $now variable to get the correct timestamp. Can you approve this post below and check to see if it starts showing in the list.
hidden link

Approve it from the frontend and let me know if it shows up now.

I did a test with the Date Created and the Draft posts that I made from the form with the updated code and they show up, so I will like for you to check to see if it now shows with the Date Approved .

Thanks,
Shane

#2000731

Unfortunately, this is still not working.

I approved requisition 1990 hidden link from the front end

the approved date of 1616630400 seems to match, but the requisition still doesn't show in the filtered view at hidden link

Really don't know what I am missing here...

#2000759

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2021-03-25 at 10.07.44 AM.png

Hi James,

This should be working now. I saw that you set the filter to a DATE however given that we are comparing Timestamps which are numeric values then the filter should be set to NUMBER see screenshot.

Please let me know if this helps.
Thanks,
Shane