Apologies if a similar question has already been asked, but I can't seem to find the exact functionality I am looking for.
Basically I have a custom post type (sermons) which has 'recorded_date' as a custom meta data field. What I would like to do is on the custom post admin page (where all posts are shown) is change the existing date filter action to filter by this 'recorded_date' field and not the post_date as it normally does. I've managed to change the date filter dropdown using the following:
add_filter('months_dropdown_results', 'custom_date_dropdown');
function custom_date_dropdown($months){
global $wpdb;
$months = $wpdb->get_results("SELECT DISTINCT YEAR( meta_value ) AS year,
MONTH(meta_value) AS month FROM wp_postmeta
WHERE meta_key = 'recorded_date' ORDER BY meta_value DESC");
return $months;
}
Which works perfectly. But selecting any value and filtering filters against the post_date. Is there anyway I can intercept this behaviour and change the filter query to my own custom query? Or I am I better off removing the filter and adding a custom one from scratch?
Thanks for any help in advance.