Comparing meta_value when it's dates
-
Hi guys,
i’m doing a booking system for a small hotel and i have a problem in a function. This function aims to return the price indicator depending on the date. This indicator is “low” or “high”.
The client can create many periods, for example beginning of december, end of december, christmas weekend etc…. and determines which price indicator is linked the period.
For example christmas weekend will be a high price, and begiinig of december will be low price.
Each room type of the hotel has a price depending on the period.
function get_price_indicator( $date )
{
global $wpdb;$exploded_date = explode(‘-‘, $date); // dd/mm/yyyy
$date = mktime(0,0,0, $exploded_date[1], $exploded_date[0], $exploded_date[2]);query_posts(‘post_type=periods
&post_status=publish
&meta_key=date_begins
&meta_compare=<=
&meta_value=’.$date.’
&meta_key=date_ends
&meta_compare=>=
&meta_value=’.$date.’
&orderby=meta_value_num’);if (have_posts()) :
while (have_posts()) : the_post();
return “”.get_post_meta(get_the_ID(), ‘price_indicator’, true).””;
endwhile;
else :
return “low”;
endif;
}The function tries to fin a perdiod in which the date is making part of. The matter is that the meta_value field are formated with the mktime() function and is stored as a text field in mysql by wordpress not in a INT format so i cannot compare them.
Anyone could help me on comparing the comparison of these dates? The aim is to return “low” or “high” if $date is making part of a period beginning at date_starts and ending at date_ends.
many thanks !
- The topic ‘Comparing meta_value when it's dates’ is closed to new replies.