Skip Navigation

[Resolved] Use date custom field to determine if post should be shown but only if it exists

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

This topic contains 1 reply, has 2 voices.

Last updated by Beda 4 years, 2 months ago.

Author
Posts
#1487855

I have a list of events showing.

Some events:
- have a start date. If this is the case, my view shows the start date. This works
- have an end date. If this is the case, I want to filter these out if the end date has passed

I can't get the second one working. I've added the END DATE recently, after the posts have been created. This means (from what I can tell) that posts wouldn't have any record at all for this. That's ok

For the handful of events with end dates, I can set this.

I need to filter events that DO have an end date, and if it's PASSED.

I can't seem to do this though

#1488325

You would need a view that filters between dates.
https://toolset.com/forums/topic/search-a-date-between-start-date-and-end-date/#post-823107

This is also explained here:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-date/#compare-against-a-group-of-dates

But since you use 2 dates (a start and finish) you can't use those approaches which filter between compared to ONE date field on the post.

Instead, you'd set up the filter to filter greater than the (start) date and smaller than the (end) date when inserting the filter.
You would have 2 inputs on the front end, for the start date, and end date.
Selecting a date in each would filter posts with dates in the first (start) greater than that value, and dates in the second input (end) smaller than the value set.

This would work exactly as an inbetween filter between 2 date fields.

Here is the Search Filter that the GUI produced on my View, when I used 2 date field, end and start.

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
	<label for="wpv-wpcf-start">[wpml-string context="wpv-views"]date[/wpml-string]</label>
	[wpv-control-postmeta type="date" field="wpcf-start" url_param="wpv-wpcf-start"]
</div>
<div class="form-group">
	<label for="wpv-wpcf-end">[wpml-string context="wpv-views"]end[/wpml-string]</label>
	[wpv-control-postmeta type="date" field="wpcf-end" url_param="wpv-wpcf-end"]
</div>[wpv-filter-submit output="bootstrap"][/wpv-filter-controls]
[wpv-filter-end]

Does this help?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.