[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.
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"
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.
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...
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?
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:
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.
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.
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.
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 .
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.