Skip Navigation

[Resolved] I cant find a way to effectively filter a custom field with more than one query

This support ticket is created 5 years, 6 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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Beda 5 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#1285321

Tell us what you are trying to do?

I am trying to: Display a list of Calendar events, the list should only display posts which have a custom field value of greater or equal to the current time. I also want to allow users to filter between two dates.

As we can't use the same custom field more than once in the filter GUI I have used a conditional filter to filter out old dates in the content template. However, this makes pagination inaccurate and unworkable.

[wpv-conditional if="( $(wpcf-start-calendar-date) gte 'NOW()' )"]<div class="list-bdr-1">
[wpv-post-link] <span class="event-date">[types field='start-calendar-date' style='text' format='F j, Y g:i a'][/types]</span><br>
</div>[/wpv-conditional]

Filter:

Start-Calendar-Date is a string between URL_PARAM(wpv-wpcf-start-calendar-date_min), URL_PARAM(wpv-wpcf-start-calendar-date_max)

Is there a workaround for this? or am I missing something?

Link to a page where the issue can be seen: hidden link

#1285423

There is no practical way to do that natively in a View's Query and conditions.

What you can do is apply one filter to a certain Field in the GUI (as a Query filter or even as a Front End Filter), and then you can add additional filters to the same Field using Toolset Views' API:
https://toolset.com/documentation/programmer-reference/views-filters/

The hook wpv_filter_query will help you to modify the query sent to WordPress and add as many additional filters you want:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

That allows you to alter the entire query sent, and add as many or remove/alter as many arguments you need.

But maybe you can profit from some work already done by users in past:
hidden link

This could be a great starting point for the Custom Code that you will need for this.

#1285451

I think i'll need to see the knowledgebase article to get a better idea, how can I access it? Do I need an account?

#1285459

Oh, that snippet is not public.
I apologise, I did not notice it.
I have made it public now, however, consider it is an example only, you cannot use this as-is, as custom code always needs to be adapted.