Skip Navigation

[Resolved] Custom filter in View

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Waqar 1 year, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2620965
Screenshot 2023-07-04 at 3.10.37 PM.png

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?

#2621001

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

#2621305

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.