If current time is between two custom values, get post.
-
I’m currently coding an on air section for a radio website and am trying to display the title and meta data of the current show on air.
To do this I’ve created custom fields “Start Time” and “End Time” and have set up a query_posts command to retrieve the show post based on the current time being a larger value than “Start Time” and less than “End Time”.
date_default_timezone_set('Europe/London'); $time = date("G:i"); $showstart = get_post_meta($post->ID, 'Start Time', true); $showend = get_post_meta($post->ID, 'End Time', true); if($time<$showstart) {$startnext = $showstart;} if($showstart<=$time && $time<$showend) {$starttime = $showstart;} if( date( 'w' ) == 0 ) { query_posts('cat=17&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); } else if( date( 'w' ) == 1 ) { query_posts('cat=18&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); } else if( date( 'w' ) == 2 ) { query_posts('cat=12&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); } else if( date( 'w' ) == 3 ) { query_posts('cat=13&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); } else if( date( 'w' ) == 4 ) { query_posts('cat=14&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); } else if( date( 'w' ) == 5 ) { query_posts('cat=15&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); } else if( date( 'w' ) == 6 ) { query_posts('cat=16&posts_per_page=1&offset=0&orderby=met a_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC'); }
However, it’s just retrieving the first show post in the order I’ve set. Any ideas how to make it work?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘If current time is between two custom values, get post.’ is closed to new replies.