Dear Sir/Madam,
Is it possible to have a custom filter in View? I have a custom field named 'first-bill-date' and 'plan'. I have a shortcode to calculate the expiry date according to the first-bill-date and plan. Is it possible to filter by the shortcode result like the screenshot?
Hi,
Thank you for contacting us and I'd be happy to assist.
To suggest the most efficient way to achieve this, I'll need to see how these fields and the custom shortcode are set up in the admin area.
Can you please share temporary admin login details, along with the link to the page where this view is being used?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
regards,
Waqar
Thank you for sharing these details.
Looking into the website's setup, there are a couple of ways you can approach this:
1. You can add another 'date' type custom field 'Expiry Date' to this 'Members' post type.
To programmatically update the value of this field, every time a 'Member' post is created/updated, you can use a custom function attached to the 'save_post' hook:
https://developer.wordpress.org/reference/hooks/save_post/
The calculation of the expiry date would be the same as in the code for the 'expiry_date' custom shortcode.
The benefit of storing the actual expiry date value as a custom field would be that you'll be able to apply the date filters in the query filter section of the view.
OR
2. Alternatively, you can register a new custom shortcode that returns '1' if the 'expiry_date' shortcode's value is within today's timestamp value and the target number of day's timestamp value (for example 3 days from now). If not, it should return '0'.
The view's query will bring in all the results, but in the loop of the view, you can wrap the output inside the conditional statement, that checks for the new custom shortcodes value and only shows the output if it is equal to '1'.
https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/
I hope this makes sense and let me know if you have any follow-up questions.