Skip Navigation

[Closed] Multiple filter into view for date

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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 5 months, 1 week ago.

Author
Posts
#2708270

Hi,
I have a view that filters and exports data from a CPT in which there is a date (the CPT are availability dates).

To date, there is a filter on the date (date equal to the date entered in the filter).
Now I would also like the view to propose the results to me no earlier than the next 3 months.

I have tried entering a new filter in the view but I can no longer select the date field. How can I proceed?

Regards

#2708309

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The filter you have for a date field is a front-end filter where the user enters the date and then the View returns posts which match that date.

For example, if they entered the date 1 August 2024 it would show posts with that same date.

But now you would also like to return posts not just from 1 August 2024 but also up to 3 months after 1 August 2024, is that correct? (So, from 1 August 2024 to 1 November 2024.)

It is not possible to add multiple conditions for a single filter in the UI (the exception is when you choose a BETWEEN comparison, where the user can specify a start and end date).

In the UI you can update the comparison for the existing date field filter to use ">=" (greater than or equal to) the entered date. That will return posts, in my example above, from 1 August 2024 and later.

If you combined that with pagination it could show, for example, posts marked 1 August 2024 and up to 10 more posts later than 1 August 2024. (That could perhaps make more sense for your UI.)

If you did want to explicitly show up to 3 months of results after the filtered date then you would need to use the API to modify the query that returns the posts (specifically modifying the meta query condition).

You can use the Toolset API hook wpv_filter_query to modify the query arguments, see https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query. (The arguments are the same as the underlying WP_Query: https://developer.wordpress.org/reference/classes/WP_Query/#custom-field-post-meta-parameters.)

The topic ‘[Closed] Multiple filter into view for date’ is closed to new replies.