1

I query all my orders and loop over them 1 bye 1 and this is what the print looks like: (only copied 1 order) This is the dump of 1 $order

Array
(
    [0] => Array
        (
            [attractie] => WP_Post Object
                (
                    [ID] => 41
                    [post_author] => 1
                    [post_date] => 2016-02-29 14:30:33
                    [post_date_gmt] => 2016-02-29 14:30:33
                    [post_content] => Content
                    [post_title] => Title
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => post-name
                    [to_ping] => 
                    [pinged] => 
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [menu_order] => 0
                    [post_type] => attracties
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

            [start] => 0930
            [end] => 1200
            [personen] => 8
        )

)

Now my goal is to check the start and end hours of every attractie in an order to see if there are attracties overlapping each other an order can have multiple attracties.

So here's what I've tried but I always get the result no overlap.

if ( $orders->have_posts() ){
        while ($orders->have_posts()) : $orders->the_post(); 
            $order = get_field('field_56e6a0f52ce6b');
            $prevEnd = null;
            $found_overlap = false;
            foreach($order as $o){
                $attractie = $o['attractie']->post_title;
                $start = $o['start'];
                $end = $o['end'];

                if($prevEnd !== null && $start < $prevEnd){
                   $found_overlap = true;
                }

                if ($found_overlap) {
                    echo "overlap\n";
                } else {
                    echo "no overlap\n";
                }

                $prevEnd = $end;
            }

        endwhile; 
}
7
  • Include more code. I would like to see where that $order come from. Commented Apr 19, 2016 at 7:45
  • @chba the result of $order is what I posted in OP the array is the dump of $order Commented Apr 19, 2016 at 7:46
  • Cool, but I cannot see that in code. Besides, your curly brackets looks a bit off. You start if with bracket and end with endif; ? Looks weird to me. Besides, why $order is singular if you are foreach-ing it? Are there more loops that surrounds this code? Btw, there are no need to $orders->have_posts() in if and one more time at while loop. Using it at while is enough! Commented Apr 19, 2016 at 7:52
  • @chba I updated OP check it out if you want Commented Apr 19, 2016 at 7:55
  • Print out $start and $prevEnd before that if statement and check if you actually get expected dates. Commented Apr 19, 2016 at 7:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.