I have a custom date field assigned to posts that has been saved to the database in this format:
2022-06-01
I'm trying to use a query filter in a view to exclude posts with this custom field set to future dates (for example, the custom field date may be set to two weeks from now). For this view I only want to show posts where that custom date field is today or earlier. I'm attaching a screenshot of the view filter I tried, but it returned no results. I've tried other data formats in the filter but nothing is working. Is there a way to accomplish this?
Hello. Thank you for contacting the Toolset support.
I just wanted to confirm is the date custom field you are talking about is created using Types plugin or the custom field is created using third party plugin that stores the date value in database as date 2022-06-01 ?
Toolset custom date field stores its value to database as UnixTimestamp.
If you can share admin access details and tell me where you added your view with problem URL I'm happy to look at it and check what could be the possible solution I can share with you once I review your current setup.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.
There isn't a way to directly enter a filter for the date format you are working with, i.e. based on yyyy-mm-dd.
You have two options. One is to register a custom shortcode that will return the current date in the same format. You can then set up the Query Filter to treat the field as a string, where the value to compare comes from a shortcode attribute, and where you add that shortcode attribute (with its value coming from your custom shortcode) to the wpv-views shortcode used to insert the View.
Here's an example that should do what you need (it assumes you are not using any other custom field filters on the same View). You need to edit the IDs of the View(s) this should be applied to.
Thank you SO MUCH Nigel, the view filter is exactly what I needed. I remembered that there was a way to modify the View's query via a filter but I didn't know the particulars. I just needed to modify the comparison to be "<=" instead of ">=" and it worked like a charm.