0

I have two custom post type table and reservation. Also on the CPT reservation I made three custom fields date, hour and IDtable (this meta field I made to storage ID of the table, so this IDtable is saving the ID of the table queries). I want to check if is any table (e.g. I have 3 queries like table1, table2, table3) free in the date (e.g. 28.10.2021) at the hour (e.g. 20.00). How I can display this in wordpress, I think I have to use left join, but I am stuck.

Here is the custom fields for reservation

$curent_reservation_date_hour = get_post_meta ($post->ID, 'hour', true ); // 
$curent_reservation_date_day = get_post_meta ($post->ID, 'date', true ); // 
$curent_table_id = get_post_meta ($post->ID, 'IDtable', true ); // 

$arg= array(
            'posts_per_page' => -1,
            'post_type' => array(  'table', 'reservation', ),
            'meta_query' => array(
                'relation' => 'AND',
                array(
                    'key' => 'IDtable',
                    'value' => $curent_table_id,
                    'compare' => 'NOT IN'
                ),
                array(
                    'key' => 'date',
                    'value' => $curent_reservation_date_day,
                    'compare' => 'NOT IN'
                ),
                array(
                    'key' => 'hour',
                    'value' => $curent_reservation_date_hour,
                    'compare' => 'NOT IN'
                ),
                array(
                    'key' => 'id',
                    'value' => $curent_reservation_date_hour,
                    'compare' => 'NOT IN'
                ),
            )
        ); 
$queryTableReserve = new WP_Query( $arg); 
        if ( $queryTableReserve->have_posts() ) { 
            while ($queryTableReserve->have_posts()){
                $queryTableReserve->the_post(); 
                //_reservation_date_day
                echo 'Tables availabel ... '.get_the_title().'<br>';
            }//close while
            wp_reset_postdata(); 
        } else {
            echo 'results 0<br>';
        }
        wp_reset_postdata(); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.