@@ -342,18 +342,19 @@ function cablecast_schedule_shortcode($atts) {
342342 continue ;
343343 }
344344
345- $ item_time = strtotime ($ item ->run_date_time );
345+ // Use run_timestamp for timezone-safe comparisons
346+ $ item_timestamp = $ item ->run_timestamp ;
346347
347348 switch ($ mode ) {
348349 case 'remaining ' :
349350 // Only shows that haven't ended yet (assuming 30min default)
350- if ($ item_time + 1800 > $ now_timestamp ) {
351+ if ($ item_timestamp + 1800 > $ now_timestamp ) {
351352 $ filtered_items [] = $ item ;
352353 }
353354 break ;
354355 case 'next ' :
355356 // Only future shows
356- if ($ item_time > $ now_timestamp ) {
357+ if ($ item_timestamp > $ now_timestamp ) {
357358 $ filtered_items [] = $ item ;
358359 }
359360 break ;
@@ -515,7 +516,8 @@ function cablecast_now_playing_shortcode($atts) {
515516
516517 for ($ i = 0 ; $ i < count ($ items ); $ i ++) {
517518 $ item = $ items [$ i ];
518- $ item_start = strtotime ($ item ->run_date_time );
519+ // Use run_timestamp for timezone-safe comparisons
520+ $ item_start = $ item ->run_timestamp ;
519521
520522 // Get runtime from show meta if available
521523 $ show = cablecast_get_show_from_schedule ($ item );
@@ -710,12 +712,11 @@ function cablecast_weekly_guide_shortcode($atts) {
710712
711713 $ output = '<div class=" ' . implode (' ' , $ classes ) . '"> ' ;
712714
713- // Channel switcher
715+ // Channel switcher (JavaScript in shortcodes.js handles the change event)
714716 if ($ show_channel_switcher && count ($ channels ) > 1 ) {
715- $ current_url = remove_query_arg ('channel ' );
716717 $ output .= '<div class="cablecast-weekly-guide__channel-switcher"> ' ;
717718 $ output .= '<label for="cablecast-channel-select"> ' . __ ('Channel: ' , 'cablecast ' ) . '</label> ' ;
718- $ output .= '<select id="cablecast-channel-select" onchange="window.location.href= \'' . esc_url ( $ current_url ) . ' &channel= \' + this.value" > ' ;
719+ $ output .= '<select id="cablecast-channel-select"> ' ;
719720 foreach ($ channels as $ channel ) {
720721 $ selected = ($ channel ->ID === $ channel_id ) ? ' selected ' : '' ;
721722 $ output .= '<option value=" ' . esc_attr ($ channel ->ID ) . '" ' . $ selected . '> ' ;
@@ -762,8 +763,8 @@ function cablecast_weekly_guide_shortcode($atts) {
762763 $ show = cablecast_get_show_from_schedule ($ item );
763764 $ item_time = date ('g:i A ' , strtotime ($ item ->run_date_time ));
764765
765- // Determine if this is the current program
766- $ item_timestamp = strtotime ( $ item ->run_date_time ) ;
766+ // Determine if this is the current program using run_timestamp for timezone-safe comparisons
767+ $ item_timestamp = $ item ->run_timestamp ;
767768 $ is_current = false ;
768769 if ($ is_today ) {
769770 $ runtime = $ show ? (int ) get_post_meta ($ show ->ID , 'cablecast_show_trt ' , true ) : 1800 ;
@@ -1927,7 +1928,21 @@ function cablecast_home_shortcode($atts) {
19271928
19281929 // Get channels
19291930 $ channels = cablecast_get_all_channels ();
1930- $ default_channel = !empty ($ channels ) ? $ channels [0 ]->ID : 0 ;
1931+
1932+ // Check for channel in URL parameter, otherwise use first channel
1933+ $ selected_channel = 0 ;
1934+ if (isset ($ _GET ['channel ' ])) {
1935+ $ selected_channel = absint ($ _GET ['channel ' ]);
1936+ }
1937+ // Validate the channel exists in our list
1938+ $ valid_channel = false ;
1939+ foreach ($ channels as $ channel ) {
1940+ if ($ channel ->ID === $ selected_channel ) {
1941+ $ valid_channel = true ;
1942+ break ;
1943+ }
1944+ }
1945+ $ default_channel = $ valid_channel ? $ selected_channel : (!empty ($ channels ) ? $ channels [0 ]->ID : 0 );
19311946
19321947 // Get section headings from settings
19331948 $ now_playing_heading = isset ($ home_settings ['now_playing_heading ' ]) ? $ home_settings ['now_playing_heading ' ] : __ ('Now Playing ' , 'cablecast ' );
@@ -1948,11 +1963,11 @@ function cablecast_home_shortcode($atts) {
19481963 $ output .= '<section class="cablecast-home__section cablecast-home__section--now-playing"> ' ;
19491964 $ output .= '<h2 class="cablecast-home__section-heading"> ' . esc_html ($ now_playing_heading ) . '</h2> ' ;
19501965
1951- // If multiple channels, show tabs
1966+ // If multiple channels, show tabs (JavaScript in shortcodes.js handles click events)
19521967 if (count ($ channels ) > 1 ) {
19531968 $ output .= '<div class="cablecast-home__channel-tabs"> ' ;
1954- foreach ($ channels as $ index => $ channel ) {
1955- $ active = $ index === 0 ? ' cablecast-home__channel-tab--active ' : '' ;
1969+ foreach ($ channels as $ channel ) {
1970+ $ active = ( $ channel -> ID === $ default_channel ) ? ' cablecast-home__channel-tab--active ' : '' ;
19561971 $ output .= '<button type="button" class="cablecast-home__channel-tab ' . $ active . '" data-channel=" ' . esc_attr ($ channel ->ID ) . '"> ' ;
19571972 $ output .= esc_html ($ channel ->post_title );
19581973 $ output .= '</button> ' ;
@@ -2028,11 +2043,13 @@ function cablecast_home_shortcode($atts) {
20282043 $ output .= '<h3 class="cablecast-home__browse-heading"> ' . esc_html__ ('Producers ' , 'cablecast ' ) . '</h3> ' ;
20292044 $ output .= do_shortcode ('[cablecast_producers count="10" orderby="count" layout="list"] ' );
20302045
2031- $ producers_link = get_term_link ('cablecast_producer ' );
2032- // Note: get_term_link with just taxonomy returns WP_Error, so we link to shows archive instead
2033- $ output .= '<a href=" ' . esc_url ($ shows_archive ?? '# ' ) . '" class="cablecast-home__browse-link"> ' ;
2034- $ output .= __ ('All Producers ' , 'cablecast ' ) . ' → ' ;
2035- $ output .= '</a> ' ;
2046+ // Link to shows archive with browse parameter
2047+ $ producers_archive = get_post_type_archive_link ('show ' );
2048+ if ($ producers_archive ) {
2049+ $ output .= '<a href=" ' . esc_url (add_query_arg ('browse ' , 'producers ' , $ producers_archive )) . '" class="cablecast-home__browse-link"> ' ;
2050+ $ output .= __ ('All Producers ' , 'cablecast ' ) . ' → ' ;
2051+ $ output .= '</a> ' ;
2052+ }
20362053 $ output .= '</div> ' ;
20372054
20382055 $ output .= '</div> ' ; // browse-grid
0 commit comments