Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created June 28, 2024 12:44
Show Gist options
  • Save kartikparmar/8df171d8e9f42f0e878eef1dfefdf789 to your computer and use it in GitHub Desktop.
Save kartikparmar/8df171d8e9f42f0e878eef1dfefdf789 to your computer and use it in GitHub Desktop.
Fetch bookings for given product id and available comment data.
<?php
$args = array(
'post_type' => 'bkap_booking', // Replace with your actual custom post type
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_bkap_product_id',
'value' => '123',
'compare' => '='
),
array(
'key' => '_bkap_additional_comment',
'value' => '',
'compare' => '!='
)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
// Your code to display or process the booking data
$booking_id = get_the_ID();
$product_id = get_post_meta($booking_id, '_bkap_product_id', true);
$additional_comment = get_post_meta($booking_id, '_bkap_additional_comment', true);
echo 'Booking ID: ' . $booking_id . '<br>';
echo 'Product ID: ' . $product_id . '<br>';
echo 'Additional Comment: ' . $additional_comment . '<br>';
}
wp_reset_postdata();
} else {
echo 'No bookings found.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment