On my WordPress website, I have a custom post type called booking. Basically, I want to build a filter system where user can filter their posts (booking) by date range. I am using jQuery daterangepicker to select the date range now how can I implement the backend code in the WordPress theme?
I can think of WordPress hook pre_get_posts and set the day there but the problem is it will bring bookings from every month and every year. There is another problem I can’t set the date range there. Like how can I get posts published between two specific dates?
function get_custom_booking( $query ) {
if ( $query->is_main_query() && is_post_type_archive( 'booking' ) ) {
// Set the date range logic
}
}
add_action( 'pre_get_posts', 'get_custom_booking' );
I am kinda stuck here.