jonathanbardo / WP-Date-Range-Filter

Easily filter the admin list of post and custom post type with a date range.
http:/wordpress.org/plugins/date-range-filter/
GNU General Public License v2.0
15 stars 1 forks source link

Howto filter on just 1 post type by custom field #1

Open studioleland opened 9 years ago

studioleland commented 9 years ago

Hey dev,

Want to use this for the ever-popular WP Events Manager plugin to filter events by date. I just need to know how to structure your filter below to do this:

function my_date_range_filter_query_column( $column ){ return 'post_modified'; } add_filter( 'date_range_filter_query_column', 'my_date_range_filter_query_column', 10, 1 );

Post type of "event" and custom field of "_event_start_date"

studioleland commented 9 years ago

Any response on this?

jonathanbardo commented 9 years ago

It should theorically work out of the box with any custom post type but since from what I understand Events manager doesn't put the date in the post_date column you would have to implement your own pre_get_postmethod and do a meta_query accordingly.

studioleland commented 9 years ago

After some digging it looks like the meta_query should work to modify your query_args function. Everything else is in place I believe. Thanks.

jonathanbardo commented 9 years ago

Did you implement it?

studioleland commented 9 years ago

Trying this tonight.

studioleland commented 9 years ago

I did get this working! It's quite amazing:

Had to rework some of the js to remove the maxDate and modify the default date filter ranges from "Past" to "Next".

$wp_query->set( 'meta_query', array( 'relation'=>'AND', array( 'key' => '_event_start_date', //custom field start date YYYY-MM-DD 'value' => $lowerlimit, //lower limit YYYY-MM-DD 'compare' => '>=', 'type' => 'DATE' ), array( 'key' => '_event_end_date', //custom field end date YYYY-MM-DD 'value' => $upperlimit, //upper limits YYYY-MM-DD 'compare' => '<=', 'type' => 'DATE' ) ) );

studioleland commented 9 years ago

What do I need to do to restrict this filter displaying for a single post type?