Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the community forum?
All Topics
Leland

Date range filter

Hey there,

I’m hoping to filter an event custom post type by start date custom field. Please advise on best way to accomplish this if possible.

4 years, 6 months ago
Jesper
Developer

Heya!

In what format are the dates stored?

Cheers!
Jesper

4 years, 6 months ago
Leland

They are actually stored as event_start_date and event_end_date columns in a separate _em_events table outside of the _posts table. Dates formatted as 2014-11-30. However, they are recognized as custom post type posts.

4 years, 6 months ago
Leland

Also how would I limit this only to the events post type?

4 years, 5 months ago
Jesper
Developer

Admin Columns doesn’t support data from non-core tables by default. However, you could write your own column class to support this. Do you have PHP development experience yourself, or do you know a developer for such a job?

Cheers!
Jesper

4 years, 5 months ago
Michael

I’d like to have date range filtering as well. In my case, the dates are stored as custom metadata in the wp_postmeta table. Admin Column Pro allows me to filter by a specific date/time, but not by a date/time range. Frankly, filtering by a specific date/time is not particularly useful, whereas filtering by date range would be super-useful.

3 years, 6 months ago
Stefan
Developer

Hi Michael

In our latest release, this is already possible.
There are two variations:

ACF Dates: You can set the dropdown ‘Filter by’ to range to have a range filter

Custom Field dates: You’ll have to set the format to ‘Date’ before the ‘Filter by’ dropdown will be shown. There you have also the option to filter on range.

Post data fields: This is not yet available but there is a ticket for this.

3 years, 6 months ago
Michael

Hi Stefan,

Thanks for the quick reply.

I am not sure if we are talking about the same thing, as some of the terminology is confusingly similar. I will try to be as clear and specific as I can.

I am not using ACF. I have a custom post type, called “Calendar Events,” which is registered using register_post_type() from within my theme (I know it’s considered better practice to do this through a plugin, but in this case, the site in question will never use a different theme, nor get an automated upgrade to the theme.). That custom post type has a custom date field, called “Event Date,” that is stored in the standard wp_postmeta table. The data for this field contains text representing a date/time with the date and start time of the event. It is stored in the format “Y-m-d H:i:s”.

I have configured Admin Columns Pro to display this “Event Date” field as a column on the overview page for the “Calendar Event” custom posts. The configuration options for the column look like this:
Type: “Custom Field”
Label: “Event Date”
Field: “lgl_event_date”
Field Type: “Date”
Date Format: “m/d/Y h:i A”
Before: “”
After: ” GMT”
Enable filtering?: Yes
Enable sorting?: Yes
Enable editing?: No

The options that show up in the filter dropdown are:
“All Event Date”
“02/10/2016 06:30 PM”
“02/10/2016 11:30 PM”
“02/18/2016 05:00 PM”
“02/19/2016 08:00 AM”
“02/20/2016 02:30 AM”
“02/24/2016 12:00 AM”
“03/01/2016 02:15 AM”
“──────────”
“Empty”
“Not empty”

I can’t find any option for a range anywhere. Am I missing something? Or are date ranges not supported in this case?

Thanks,
-Mike D.

3 years, 6 months ago
Michael

Oh, forgot to mention that I am using Version 3.7.4.

3 years, 6 months ago
Stefan
Developer

Hi Michael,

Sorry, you’re right. Filtering on Custom Field dates (Not ACF dates) is not possible. Because dates can be stored as many different format, we cannot be sure how to filter on dates or date ranges. We use the default WordPress meta_query to filter on date ranges and more specifically we now filter on numeric dates. for exmple: where value > 20160101

In your case it would probably work, but for many other cases it would return no results when de date is stored for example as d-m-Y. ACF stores it’s data always as Ymd so that’s why we always know how to filter on those values.

3 years, 6 months ago
Michael

OK, thanks for the reply.
Is there a hack or a work-around that I can do?

Thanks,
-Mike D.

3 years, 6 months ago
Stefan
Developer

Mike,

Sorry for my late response. I did miss your latest comment on this issue.
Unfortunately there is not workaround or hack that you can use to enable range filtering yourself for now because it is now written for a very specific case.

We’re currently working on some refactoring for sorting and maybe the result of that will allow you to do it. But for now I’m not really sure.

3 years, 2 months ago
Michael

OK, thanks, Stefan.

3 years, 2 months ago
Stefan
Developer

Just an update.
Range filtering for the the WordPress date will be available in 4.0.

3 years, 1 month ago

You must be logged in to reply to this topic.