pull data from booking database with ShortCodes or API

Hey @thomasnordic,

You can add the code below to your theme’s functions.php file. It will create a shortcode that you can add on any page to display future bookings. You can also include details such form data by searching for a field’s value.

add_shortcode('wpbs-bookings', function ($atts, $content = null) {
    $bookings = wpbs_get_bookings(array('calendar_id' => $atts['calendar_id'], 'orderby' => 'start_date', 'order' => 'asc'));
    $output="<div class="wpbs-custom-bookings">";
    foreach ($bookings as $booking) {
        if (strtotime($booking->get('start_date')) < current_time('timestamp')) {
            continue;
        }

        $fields = $booking->get('fields');

        $name = $fields[array_search('155', array_column($fields, 'id'))]['user_value']; // 155 is the form field ID for the "name" field.

        $output .= '<div class="wpbs-custom-booking">'
         . date('d.m.', strtotime($booking->get('start_date'))) . ' - '
         . date('d.m.y', strtotime($booking->get('end_date'))) . ': '
         . $name .
        '</div>';
    }
    $output .= '</div>';
    return $output;
});

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer