Hi Support
I am struggling to get posts displayed in a view which are about to expire.
I've already set up automatic expiration of posts of type Job Ads as described in https://toolset.com/course-lesson/setting-up-automatic-post-expiration, which is a nice, useful feature but lacks some fundamental functionality in my opinion, resulting in it being difficult to work with the Expiry Date in queries later.
The value stored in wp_postmeta as a UNIX number is not easy or intuitive to use as query filter condition without using Custom Code again.
Our requirements are:
(1) display the Job Ad post expiry date on a list of posts. I found how to do this already, using the shortcode [cred-post-expiration id="[wpv-post-id]" format="m/d/Y"]. It would also make sense to add this to your documentation somewhere in https://toolset.com/course-lesson/setting-up-automatic-post-expiration.
(2) display a view filtering Job Ad posts expiring in the coming 30 days
(3) display a view filtering Job Ad posts which have expired
Ideally, this should be an easy, intutive task, eg by choosing expiry date in the query filter between TODAY and TODAY+30 for (2) and > TODAY for (3), however the expiry date is not available in the query filter section picklist.
I thought of several approaches to how this could be solved:
1) Toolset Code Change
- Toolset makes this date available somehow as an option in the query section, eg as "Custom field -cred_post_expiration_date"
2) On saving the form, use a hidden field to generate a "TODAY + x DAYS" and store it as eg POST EXPIRY DATE on the Job Ad post type.
3) I then thought of approching it by querying using the Post Date, since it is the reference point for the expiry date anyway, however that failed, due to how the Post Date query works.
3a) In our dev environment all of our test Job Ads are created in this month, August 2020. So, I tried, for example, Post Date with Day between PAST_ONE 30 and CURRENT_ONE, (thinking this was the same as between TODAY-30 and TODAY) but this didn't work with any value above the current day. I suspect this may be because in the background it is doing 23 - 30 = -7 and not being able to interpret -7 as a real day of month.
3b) I can't use BETWEEN (Day=CURRENT_ONE and Month=CURRENT_ONE) and (Day=CURRENT_ONE and Month=PAST_ONE(1)), since this would not work for all days in the calendar, especially February. Also not clear how it would handle posts in January, giving perhaps 1 - 1 = 0 for the month.
3c) Similary post date older than between 155 and 185 days wouldn't work for the same reasons.
Am I overthinking this or have I missed something basic?! Or is there any easy way to achieve our simple requirements using existing query functions without custom code again? I imagine the first thing all developers would try to do using the Expiry Date is to query a list of expiring and expired posts.
If I am right about how the Post Date filtering is working currently, then please rename the following elements in the user interface to reflect what we are actually specifying for the query, valid values in brackets would help greatly here. It was already partly done for "Day of the year" and "Day of the week" but omitted for all other elements. This should reflect what is described in https://toolset.com/documentation/user-guides/views/filtering-views-query-by-date/.
a) Year >> OK
b) Month >> Month of year (or specify 1 - 12 in brackets)
c) Week >> Week of year (or specify 1 - 53 in brackets), also please specify what calendar standard is being used in the documentation ... ISO?
d) Day >> Day of month (or specify 1 - 31 in brackets)
e) Day of the year >> (OK, but specify 1 - 366 in brackets)
f) Day of the week, this was clarified in documentation already ie 1 - 7, also depending on whether you think Sunday is start of week (ie a 1) or a weekend day (ie a 7)
g) Hour >> Hour of day (or specify 0 - 23 in brackets)
h) Minute >> Minute of hour (or specify 0 - 59 in brackets)
i) Second >> Second of minute (or specify 0 - 59 in brackets)
Thanks and regards
Simon