Advertisement
salvatorifabio

availability search

Nov 17th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. /*
  2. Modify current search by adding where clause to cquery fetching posts
  3. */
  4. function custom_posts($where, $query){
  5. global $wpdb;
  6. $booking_table = $wpdb->prefix . "booking_history";
  7. $meta_table = $wpdb->prefix . "postmeta";
  8. $post_table = $wpdb->prefix . "posts";
  9. if(!empty($_GET["w_check_in"]) && $query->is_main_query()){
  10. $chkin = $_GET["w_checkin"];
  11. $chkout = $_GET["w_checkout"];
  12.  
  13. $start_date = $chkin;
  14. $end_date = $chkout;
  15.  
  16. $where = " AND($wpdb->posts.post_type = 'product'and $wpdb->posts.post_status = 'publish') AND $wpdb->posts.ID NOT IN
  17. (SELECT b.post_id FROM $booking_table AS b
  18. WHERE ('$start_date' between b.start_date and date_sub(b.end_date,INTERVAL 1 DAY))
  19. or
  20. ('$end_date' between b.start_date and date_sub(b.end_date,INTERVAL 1 DAY))
  21. or
  22. (b.start_date between '$start_date' and '$end_date')
  23. or
  24. b.start_date = '$start_date'
  25. )and $wpdb->posts.ID NOT IN(SELECT post_id from $meta_table
  26. where meta_key = 'woocommerce_booking_settings' and meta_value LIKE '%booking_enable_date\";s:0%') and $wpdb->posts.ID NOT IN(SELECT a.id
  27. FROM $post_table AS a
  28. LEFT JOIN $meta_table AS b ON a.id = b.post_id
  29. AND (
  30. b.meta_key = 'woocommerce_booking_settings'
  31. )
  32. WHERE b.post_id IS NULL)";
  33.  
  34.  
  35. }
  36. return $where;
  37.  
  38. }
  39. add_filter( 'posts_where','custom_posts', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement