Home Forums General Issues How can I filter based on number of days?


How can I filter based on number of days?

  • Hello, I am a basic acf user. My goal is to create custom fields and filter sections for a hotel website.

    I want to add start and end dates for rooms. At the same time, the number of days between these two dates is important to me. For example, a user wants to enter on April 1st and exit on April 3rd. In the filtering section, I want to show rooms that start on April 1st and have a duration of at least 3 days. How can I do this, paid or free?

    I may have explained it a bit complicated, but I want it to work the same as standard hotel sites with start and end dates.

  • I’d imagine instead of saying duration of 3 days, just take the dates and check for posts that have availability on all days in question. So check if a room is available on ALL April 1st, 2nd, and 3rd. If all dates are available then show it.

    Without knowing to much about the project I’d imagine this to check a calendar and just loop through the dates between the start and end dates and check for each day is available on the calendar.

    $desired_dates = array();
    for ($date = $start_date; $date <= $end_date; $date->modify('+1 day')) {
        $desired_dates[] = $date->format('Y-m-d');

    Hope this helps 👍 code is untested

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.