Skip to content

Instantly share code, notes, and snippets.

@rayflores
Last active August 29, 2015 14:11
Show Gist options
  • Save rayflores/3108763fb453ff653375 to your computer and use it in GitHub Desktop.
Save rayflores/3108763fb453ff653375 to your computer and use it in GitHub Desktop.
logic behind this....
<?php
function basext_bookings_query( $query ) {
if (!is_admin()){
if(isset($_REQUEST['checkin_date'])) {
$from_date = $_REQUEST['checkin_date'];
$from_date = date("Y-m-d", strtotime($from_date));
}
if(isset($_REQUEST['checkout_date'])) {
$to_date = $_REQUEST['checkout_date'];
$to_date = date("Y-m-d", strtotime($to_date));
}
global $wpdb;
global $no_match_ids;
$query_cus = "SELECT * FROM wp_postmeta WHERE meta_key = '_wc_booking_availability'";
$results = $wpdb->get_results($query_cus);
if(!empty($results)) {
foreach($results as $cfs) {
$posters = $cfs->post_id; // post ID
$un_data = unserialize($cfs->meta_value); // meta_values
$un_data = $un_data[0]; // first level
//$postID = $un_data->post_id;
$first_date = $un_data['from'];
$sec_date = $un_data['to'];
$date_from = date("Y-m-d", strtotime($first_date)); // from date stored in meta values
$date_to = date("Y-m-d", strtotime($sec_date)); // to date stored in meta values
if ($date_from = '1970-01-01') {
$no_match_ids = $posters;
print_r($no_match_ids);echo ' <-- this is one<br/>';// . $date_from . ' v ' . $from_date . '<br />';
}
// if (($date_from < $from_date)) {
// print_r($date_to);echo '<br />';
/*echo $from_date;
echo "<br>";
echo $date_form;
echo "<br>";
echo $to_date;
echo "<br>";
echo $date_to;
echo "<br>";*/
if (!($date_from <= $from_date)){ //&& $to_date<=$date_to) {
if( $query->is_main_query() & !$query->is_feed() && !is_admin() && is_post_type_archive( 'product' )) {
$meta_query = array(
array(
'key' => '_wc_booking_qty',
'type' => 'numeric',
'value' => 1,
'compare' => '>='
),
/*array(
'key' => '_wc_booking_availability',
'value' => $date_form,
'compare' => '>=',
),
array(
'key' => '_wc_booking_availability',
'value' => $date_to,
'compare' => '<=',
),*/
);
//setup_postdata($match_ids);
$query->set('post_type', 'product');
$query->set( 'meta_query', $meta_query );
$query->set( 'order', 'ASC' );
$query->set( 'posts_per_page', '4' );
$query->set('post__not_in', $no_match_ids);
}
}
}
} // get_results
} // !is_admin
}
echo $GLOBALS['wp_query']->request;
add_action( 'pre_get_posts', 'basext_bookings_query' );
@rayflores
Copy link
Author

search for dates in bottom left corner Check-In Date: 12-12-2014 Check-out Date: 1-31-2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment