get_results("select post_id from wp_postmeta where meta_key = 'on_air_day' and meta_value = '$day'"); //print_r($results); foreach ($results as $t) { $post_id = $t->post_id; /* Estraggo la fascia oraria e controllo ne $now è contenuto nel range */ $start = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = 'on_air_start' and post_id = '$post_id'"); $end = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = 'on_air_end' and post_id = '$post_id'"); $s = $start[0]->meta_value; $e = $end[0]->meta_value; /* echo "
";
		echo "$s $e";
		echo "
"; */ $begin = new DateTime("$s"); $end = new DateTime("$e"); if ($now >= $begin && $now <= $end) { $done = true; //echo get_post($post_id)->post_title; return get_post($post_id)->post_title; break; } } /* inizio check repliche */ if (!$done) { /* Cerco nelle repliche */ $rerun_today = []; $tocheck = []; /* Prendo dalla tabella wp_postmeta le trasmissioni con una replica oggi */ for ($i=0; $i <=6; $i++) { $rerun = "rerun_day_$i"; $results = $wpdb->get_results("select post_id from wp_postmeta where meta_key = '$rerun' and meta_value = '$day'"); /* echo "
";
			print_r($results);	
			echo "
"; */ foreach ($results as $t) { $tocheck[0] = $i; $tocheck[1] = $t->post_id; array_push($rerun_today,$tocheck); } } foreach ($rerun_today as $t) { $rerun_start = "rerun_start_$t[0]"; $rerun_end = "rerun_end_$t[0]"; $start = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = '$rerun_start' and post_id = '$t[1]'"); $end = $wpdb->get_results("select meta_value from wp_postmeta where meta_key = '$rerun_end' and post_id = '$t[1]'"); $s = $start[0]->meta_value; $e = $end[0]->meta_value; /* echo "
";
			print_r($s);	
			print_r($e);	
			echo "
"; */ $begin = new DateTime("$s"); $end = new DateTime("$e"); /* echo "
";
			print_r($now);	
			echo "
"; */ if ($now >= $begin && $now <= $end) { $done = true; //echo get_post($post_id)->post_title; return get_post($t[1])->post_title; break; } } } /* fine check repliche */ if (!$done) { //echo "Selezione musicale"; return "Selezione musicale"; } } add_shortcode('whatplaynow', 'what_play_now'); ?>