php - Strange behaviour on $get parameter. -
this question has answer here:
i'm getting following error "notice: undefined index:" on 'name' => $_get['channel'].
when there's parameter works , allows loop proceed, when there's no parameter set error above.
if try isset removes error stops wordpress loop proceeding if parameter set.
what missing?
<?php $args = array ( 'post_type' => 'abc_channels', 'name' => $_get['channel'], 'post_status' => 'publish', 'posts_per_page' => 1, ); $loop = new wp_query( $args ); // if have live channels if (isset($_get['channel'])) : if($loop->have_posts()): while($loop->have_posts()): $loop->the_post(); ?>
thanks @aynber pointing me solution.
<?php $channelvalue = ""; //initialization value; examples //"" when want append stuff later //0 when want add numbers later //isset() $channelvalue = isset($_get['channel']) ? $_get['channel'] : ''; //empty() $channelvalue = !empty($_get['channel']) ? $_get['channel'] : ''; ?> <?php $args = array ( 'post_type' => 'abc_channels', 'name' => $channelvalue, 'post_status' => 'publish', 'posts_per_page' => 1, ); $loop = new wp_query( $args ); // if have live channels if (isset($_get['channel'])) : if($loop->have_posts()): while($loop->have_posts()): $loop->the_post(); ?>
Comments
Post a Comment